Merge pull request #5647 from jjaffeux/empty-is-not-emoji

FIX: do not treat :: as a valid emoji
This commit is contained in:
Arpit Jalan 2018-03-05 18:46:59 +04:00 committed by GitHub
commit d9d494316a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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