diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 3ce223f9dbd..29d0d974ec0 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -53,7 +53,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document when "img" attributes = Hash[*attributes.flatten] - if attributes["class"] == 'emoji' + if attributes["class"]&.include?('emoji') if @remap_emoji title = (attributes["alt"] || "").gsub(":", "") title = Emoji.lookup_unicode(title) || attributes["alt"] diff --git a/spec/models/user_profile_spec.rb b/spec/models/user_profile_spec.rb index bd9a13616ef..7ae25e14cdc 100644 --- a/spec/models/user_profile_spec.rb +++ b/spec/models/user_profile_spec.rb @@ -102,6 +102,23 @@ describe UserProfile do end end + describe 'bio excerpt emojis' do + let(:user) { Fabricate(:user) } + + before do + CustomEmoji.create!(name: 'test', upload_id: 1) + Emoji.clear_cache + + user.user_profile.bio_raw = "hello :test: :woman_scientist:t5: 🤔" + user.user_profile.save + user.user_profile.reload + end + + it 'supports emoji images' do + expect(user.user_profile.bio_excerpt(500, keep_emoji_images: true)).to eq("hello \":test:\" \":woman_scientist:t5:\" \":thinking:\"") + end + end + describe 'bio link stripping' do it 'returns an empty string with no bio' do