FEATURE: allow blocking emojis (#7011)
https://meta.discourse.org/t/blocking-emojis-wont-work/105853
This commit is contained in:
parent
a423a9383f
commit
99c6db21e6
|
@ -19,7 +19,7 @@ class WordWatcher
|
|||
nil
|
||||
else
|
||||
regexp = '(' + words.map { |w| word_to_regexp(w) }.join('|'.freeze) + ')'
|
||||
SiteSetting.watched_words_regular_expressions? ? regexp : "\\b(#{regexp})\\b"
|
||||
SiteSetting.watched_words_regular_expressions? ? regexp : "(?<!\\w)(#{regexp})(?!\\w)"
|
||||
end
|
||||
end
|
||||
s.present? ? Regexp.new(s, Regexp::IGNORECASE) : nil
|
||||
|
|
|
@ -48,6 +48,26 @@ describe WordWatcher do
|
|||
expect(m[1]).to eq("acknowledge")
|
||||
end
|
||||
|
||||
context "emojis" do
|
||||
it "handles emoji" do
|
||||
Fabricate(:watched_word, word: ":joy:", action: WatchedWord.actions[:require_approval])
|
||||
m = WordWatcher.new("Lots of emojis here :joy:").word_matches_for_action?(:require_approval)
|
||||
expect(m[1]).to eq(":joy:")
|
||||
end
|
||||
|
||||
it "handles unicode emoji" do
|
||||
Fabricate(:watched_word, word: "🎃", action: WatchedWord.actions[:require_approval])
|
||||
m = WordWatcher.new("Halloween party! 🎃").word_matches_for_action?(:require_approval)
|
||||
expect(m[1]).to eq("🎃")
|
||||
end
|
||||
|
||||
it "handles emoji skin tone" do
|
||||
Fabricate(:watched_word, word: ":woman:t5:", action: WatchedWord.actions[:require_approval])
|
||||
m = WordWatcher.new("To Infinity and beyond! 🚀 :woman:t5:").word_matches_for_action?(:require_approval)
|
||||
expect(m[1]).to eq(":woman:t5:")
|
||||
end
|
||||
end
|
||||
|
||||
context "regular expressions" do
|
||||
before do
|
||||
SiteSetting.watched_words_regular_expressions = true
|
||||
|
|
Loading…
Reference in New Issue