mirror of
https://github.com/discourse/discourse.git
synced 2025-04-18 03:29:04 +08:00
FIX: count emoji shortcuts in topic title
https://meta.discourse.org/t/max-emojis-in-title-set-to-0-conflicting-with-emoji-shortcuts/98368/3?u=techapj
This commit is contained in:
parent
dca830cb73
commit
ce0a51665e
@ -139,6 +139,7 @@ en:
|
||||
odd: must be odd
|
||||
record_invalid: ! 'Validation failed: %{errors}'
|
||||
max_emojis: "can't have more than %{max_emojis_count} emoji"
|
||||
emojis_disabled: "can't have emoji"
|
||||
ip_address_already_screened: "is already included in an existing rule"
|
||||
restrict_dependent_destroy:
|
||||
one: "Cannot delete record because a dependent %{record} exists"
|
||||
@ -1868,7 +1869,7 @@ en:
|
||||
sso_provider_secrets:
|
||||
key: "www.example.com"
|
||||
value: "SSO secret"
|
||||
|
||||
|
||||
search:
|
||||
within_post: "#%{post_number} by %{username}"
|
||||
types:
|
||||
|
@ -1,9 +1,10 @@
|
||||
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
|
||||
unescaped_title = PrettyText.unescape_emoji(Emoji.unicode_unescape(CGI::escapeHTML(value)))
|
||||
if unescaped_title.scan(/<img.+?class\s*=\s*'(emoji|emoji emoji-custom)'/).size > SiteSetting.max_emojis_in_title
|
||||
record.errors.add(
|
||||
attribute, :max_emojis,
|
||||
attribute, SiteSetting.max_emojis_in_title > 0 ? :max_emojis : :emojis_disabled,
|
||||
max_emojis_count: SiteSetting.max_emojis_in_title
|
||||
)
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ describe MaxEmojisValidator do
|
||||
shared_examples "validating any topic title" do
|
||||
it 'adds an error when emoji count is greater than SiteSetting.max_emojis_in_title' do
|
||||
SiteSetting.max_emojis_in_title = 3
|
||||
record.title = '🧐 Lots of emojis here 🎃 :joy: :sunglasses:'
|
||||
record.title = '🧐 Lots of emojis here 🎃 :joy: :)'
|
||||
validate
|
||||
expect(record.errors[:title][0]).to eq(I18n.t("errors.messages.max_emojis", max_emojis_count: 3))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user