From 506572bf0416078784517cb6e8b34647756568bd Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 15 Aug 2017 10:05:09 +0200 Subject: [PATCH] FIX: display emojis (set, custom and native) in bio excerpt --- lib/excerpt_parser.rb | 2 +- spec/models/user_profile_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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