A platform for community discussion. Free, open, simple.
FEATURE: allow blocking emojis (#7011)
Arpit Jalan99c6db21e632
diff --git a/app/services/word_watcher.rb b/app/services/word_watcher.rbindex ff82f36bd55..20614d23a7f 100644--- a/app/services/word_watcher.rb+++ b/app/services/word_watcher.rb@@ -19,7 +19,7 @@ class WordWatchernilelseregexp = '(' + 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)"endends.present? ? Regexp.new(s, Regexp::IGNORECASE) : nildiff --git a/spec/services/word_watcher_spec.rb b/spec/services/word_watcher_spec.rbindex 52264cf41af..48ce215e43a 100644--- a/spec/services/word_watcher_spec.rb+++ b/spec/services/word_watcher_spec.rb@@ -48,6 +48,26 @@ describe WordWatcher doexpect(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" dobefore doSiteSetting.watched_words_regular_expressions = true