mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user