FIX: do not treat :: as a valid emoji

This commit is contained in:
Joffrey JAFFEUX 2018-03-05 15:35:24 +01:00
parent 057fa049e6
commit ce1994beea
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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