FEATURE: allow blocking emojis (#7011)

https://meta.discourse.org/t/blocking-emojis-wont-work/105853
This commit is contained in:
Arpit Jalan 2019-02-15 20:55:48 +05:30 committed by GitHub
parent a423a9383f
commit 99c6db21e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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