mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Add validation to disallow censored words in topic title.
This commit is contained in:
15
lib/validators/censored_words_validator.rb
Normal file
15
lib/validators/censored_words_validator.rb
Normal 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
|
Reference in New Issue
Block a user