From 3ff0800e5093c698babe83f47dec7378df374186 Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Wed, 6 Mar 2019 12:49:17 +0100 Subject: [PATCH] =?UTF-8?q?FIX:=20Fixed=20custom=20emoji=20circumventing?= =?UTF-8?q?=20"max=20emojis=20in=20topic=20title"=20set=E2=80=A6=20(#7116)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pretty_text.rb | 3 ++- spec/components/validators/max_emojis_validator_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index e3a89fe4611..d4d8ce56f87 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -230,10 +230,11 @@ module PrettyText return title unless SiteSetting.enable_emoji? set = SiteSetting.emoji_set.inspect + custom = Emoji.custom.map { |e| [e.name, e.url] }.to_h.to_json protect do v8.eval(<<~JS) __paths = #{paths_json}; - __performEmojiUnescape(#{title.inspect}, { getURL: __getURL, emojiSet: #{set} }); + __performEmojiUnescape(#{title.inspect}, { getURL: __getURL, emojiSet: #{set}, customEmoji: #{custom} }); JS end end diff --git a/spec/components/validators/max_emojis_validator_spec.rb b/spec/components/validators/max_emojis_validator_spec.rb index 671caaea999..1242a32a4e8 100644 --- a/spec/components/validators/max_emojis_validator_spec.rb +++ b/spec/components/validators/max_emojis_validator_spec.rb @@ -14,7 +14,9 @@ describe MaxEmojisValidator do shared_examples "validating any topic title" do it 'adds an error when emoji count is greater than SiteSetting.max_emojis_in_title' do SiteSetting.max_emojis_in_title = 3 - record.title = '🧐 Lots of emojis here 🎃 :joy: :)' + CustomEmoji.create!(name: 'trout', upload: Fabricate(:upload)) + Emoji.clear_cache + record.title = '🧐 Lots of emojis here 🎃 :trout: :)' validate expect(record.errors[:title][0]).to eq(I18n.t("errors.messages.max_emojis", max_emojis_count: 3))