FIX: Add validation to disallow censored words in topic title.

This commit is contained in:
Guo Xiang Tan
2017-01-09 16:48:10 +08:00
parent cbc6aee137
commit 3d21ccd4a5
4 changed files with 63 additions and 3 deletions

View File

@ -0,0 +1,15 @@
class CensoredWordsValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value =~ /#{SiteSetting.censored_words}/i
record.errors.add(
attribute, :contains_censored_words,
censored_words: SiteSetting.censored_words
)
elsif value =~ /#{SiteSetting.censored_pattern}/i
record.errors.add(
attribute, :matches_censored_pattern,
censored_pattern: SiteSetting.censored_pattern
)
end
end
end