mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Escape regexp chars in SiteSetting.censored_words
.
This commit is contained in:

committed by
Guo Xiang Tan

parent
8fc7420f83
commit
25516874b5
@ -1,7 +1,7 @@
|
||||
class CensoredWordsValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if !SiteSetting.censored_words.blank? &&
|
||||
!(censored_words = value.scan(/#{SiteSetting.censored_words}/i)).empty?
|
||||
!(censored_words = value.scan(censored_words_regexp)).empty?
|
||||
|
||||
record.errors.add(
|
||||
attribute, :contains_censored_words,
|
||||
@ -22,6 +22,13 @@ class CensoredWordsValidator < ActiveModel::EachValidator
|
||||
def join_censored_words(censored_words)
|
||||
censored_words.map!(&:downcase)
|
||||
censored_words.uniq!
|
||||
censored_words.join(", ")
|
||||
censored_words.join(", ".freeze)
|
||||
end
|
||||
|
||||
def censored_words_regexp
|
||||
Regexp.new(
|
||||
SiteSetting.censored_words.split('|'.freeze).map! { |w| Regexp.escape(w) }.join('|'.freeze),
|
||||
true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user