discourse/app/serializers/watched_word_serializer.rb
Bianca Nenciu 74f7295631
FIX: Add word boundaries to replace and tag watched words ()
The generated regular expressions did not contain \b which matched
every text that contained the word, even if it was only a substring of
a word.

For example, if "art" was a watched word a post containing word
"artist" matched.
2021-06-18 18:54:06 +03:00

18 lines
347 B
Ruby

# frozen_string_literal: true
class WatchedWordSerializer < ApplicationSerializer
attributes :id, :word, :regexp, :replacement, :action
def regexp
WordWatcher.word_to_regexp(word, whole: true)
end
def action
WatchedWord.actions[object.action]
end
def include_replacement?
WatchedWord.has_replacement?(action)
end
end