mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Abort CensoredWordsValidator early if censored_words_regexp nil (#8375)
* Abort CensoredWordsValidator early if censored_words_regexp nil. Sometimes censored_words_regex can end up nil, erroring the validator. This handles the nil condition and also adds a spec for the validator
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
|
||||
class CensoredWordsValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if WordWatcher.words_for_action(:censor).present? && (censored_words = censor_words(value, censored_words_regexp)).present?
|
||||
words_regexp = censored_words_regexp
|
||||
if WordWatcher.words_for_action(:censor).present? && !words_regexp.nil?
|
||||
censored_words = censor_words(value, words_regexp)
|
||||
return if censored_words.blank?
|
||||
record.errors.add(
|
||||
attribute, :contains_censored_words,
|
||||
attribute,
|
||||
:contains_censored_words,
|
||||
censored_words: join_censored_words(censored_words)
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user