diff --git a/lib/validators/max_emojis_validator.rb b/lib/validators/max_emojis_validator.rb index f208f66b1e0..3476cd9c011 100644 --- a/lib/validators/max_emojis_validator.rb +++ b/lib/validators/max_emojis_validator.rb @@ -1,7 +1,7 @@ class MaxEmojisValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - if Emoji.unicode_unescape(value).scan(/:([\w\-+]*(?::t\d)?):/).size > SiteSetting.max_emojis_in_title + if Emoji.unicode_unescape(value).scan(/:([\w\-+]+(?::t\d)?):/).size > SiteSetting.max_emojis_in_title record.errors.add( attribute, :max_emojis, max_emojis_count: SiteSetting.max_emojis_in_title diff --git a/spec/components/validators/max_emojis_validator_spec.rb b/spec/components/validators/max_emojis_validator_spec.rb index a81bed2fb8d..351746e44b0 100644 --- a/spec/components/validators/max_emojis_validator_spec.rb +++ b/spec/components/validators/max_emojis_validator_spec.rb @@ -17,6 +17,10 @@ describe MaxEmojisValidator do record.title = '🧐 Lots of emojis here 🎃 :joy: :sunglasses:' validate expect(record.errors[:title][0]).to eq(I18n.t("errors.messages.max_emojis", max_emojis_count: 3)) + + record.title = ':joy: :blush: :smile: is not only about emojis: Happyness::start()' + validate + expect(record.valid?).to be true end end