mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user