FIX: Use only first character when looking up emoji (#22977)

The other characters may be variation selectors and result in a
false-negative.
This commit is contained in:
Bianca Nenciu
2023-08-04 15:28:58 +02:00
committed by GitHub
parent 207d983809
commit 1d58dcac1f
2 changed files with 21 additions and 6 deletions

View File

@ -9,20 +9,33 @@ RSpec.describe MaxEmojisValidator do
end
shared_examples "validating any topic title" do
it "adds an error when emoji count is greater than SiteSetting.max_emojis_in_title" do
before do
SiteSetting.max_emojis_in_title = 3
CustomEmoji.create!(name: "trout", upload: Fabricate(:upload))
Emoji.clear_cache
end
it "adds an error when emoji count is greater than SiteSetting.max_emojis_in_title" do
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),
)
end
it "does not add an error when emoji count is exactly SiteSetting.max_emojis_in_title" do
record.title = ":joy: :blush: :smile: is not only about emojis: Happiness::start()"
validate
expect(record.valid?).to be true
end
it "counts emojis with variation selectors" do
record.title = "Title with emojis ☠️☠️☠️☠️"
validate
expect(record.errors[:title][0]).to eq(
I18n.t("errors.messages.max_emojis", max_emojis_count: 3),
)
end
end
describe "topic" do