FIX: Don't cook user fields to apply watched words (#17590)

The previous method for reused the PrettyText logic which applied the
watched word logic, but had the unwanted effect of cooking the text too.
This meant that regular text values were converted to HTML.

Follow up to commit 5a4c35f627.
This commit is contained in:
Bianca Nenciu
2022-07-26 18:15:42 +03:00
committed by GitHub
parent 171789f47a
commit 5f13ca5e54
6 changed files with 101 additions and 51 deletions

View File

@@ -99,7 +99,7 @@ class WordWatcher
end
def self.censor(html)
regexp = WordWatcher.word_matcher_regexp(:censor)
regexp = word_matcher_regexp(:censor)
return html if regexp.blank?
doc = Nokogiri::HTML5::fragment(html)
@@ -110,12 +110,24 @@ class WordWatcher
end
def self.censor_text(text)
regexp = WordWatcher.word_matcher_regexp(:censor)
regexp = word_matcher_regexp(:censor)
return text if regexp.blank?
censor_text_with_regexp(text, regexp)
end
def self.apply_to_text(text)
if regexp = word_matcher_regexp(:censor)
text = censor_text_with_regexp(text, regexp)
end
%i[replace link]
.flat_map { |type| word_matcher_regexps(type).to_a }
.reduce(text) do |t, (word_regexp, replacement)|
t.gsub(Regexp.new(word_regexp)) { |match| "#{match[0]}#{replacement}" }
end
end
def self.clear_cache!
WatchedWord.actions.each do |a, i|
Discourse.cache.delete word_matcher_regexp_key(a)