From ce1994beea4d85f58810a7e06fd851751ba512e6 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 5 Mar 2018 15:35:24 +0100 Subject: [PATCH] FIX: do not treat :: as a valid emoji --- lib/validators/max_emojis_validator.rb | 2 +- spec/components/validators/max_emojis_validator_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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