mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 12:42:57 +08:00
ce0a51665e
https://meta.discourse.org/t/max-emojis-in-title-set-to-0-conflicting-with-emoji-shortcuts/98368/3?u=techapj
13 lines
513 B
Ruby
13 lines
513 B
Ruby
class MaxEmojisValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
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, SiteSetting.max_emojis_in_title > 0 ? :max_emojis : :emojis_disabled,
|
|
max_emojis_count: SiteSetting.max_emojis_in_title
|
|
)
|
|
end
|
|
end
|
|
end
|