Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
alert_words: Fix highlighting of adjacent alert words.
im-adithya009b7bca2411
diff --git a/frontend_tests/node_tests/alert_words.js b/frontend_tests/node_tests/alert_words.jsindex 08303f23f8c..dbd08c725bd 100644--- a/frontend_tests/node_tests/alert_words.js+++ b/frontend_tests/node_tests/alert_words.js@@ -67,6 +67,12 @@ const question_word_message = {alerted: true,};+const typo_word_message = {+ sender_email: "[email protected]",+ content: "<p>alertones alerttwo alerttwo alertthreez</p>",+ alerted: true,+};+const alert_domain_message = {sender_email: "[email protected]",content:@@ -137,6 +143,11 @@ run_test("munging", () => {"<p>still <span class='alert-word'>alertone</span>? me</p>",);+ assert_transform(+ typo_word_message,+ "<p>alertones <span class='alert-word'>alerttwo</span> <span class='alert-word'>alerttwo</span> alertthreez</p>",+ );+assert_transform(alert_domain_message,'<p>now with link <a href="http://www.alerttwo.us/foo/bar" target="_blank" title="http://www.alerttwo.us/foo/bar">www.<span class=\'alert-word\'>alerttwo</span>.us/foo/bar</a></p>',diff --git a/static/js/alert_words.js b/static/js/alert_words.jsindex 4c0a8bfe49e..74a0464c5d5 100644--- a/static/js/alert_words.js+++ b/static/js/alert_words.js@@ -32,8 +32,8 @@ export function process_message(message) {for (const word of my_alert_words) {const clean = _.escapeRegExp(word);- const before_punctuation = "\\s|^|>|[\\(\\\".,';\\[]";- const after_punctuation = "\\s|$|<|[\\)\\\"\\?!:.,';\\]!]";+ const before_punctuation = "(?<=\\s)|^|>|[\\(\\\".,';\\[]";+ const after_punctuation = "(?=\\s)|$|<|[\\)\\\"\\?!:.,';\\]!]";const regex = new RegExp(`(${before_punctuation})(${clean})(${after_punctuation})`, "ig");message.content = message.content.replace(diff --git a/zerver/tests/test_alert_words.py b/zerver/tests/test_alert_words.pyindex 5ce78237ef8..aff9983d169 100644--- a/zerver/tests/test_alert_words.py+++ b/zerver/tests/test_alert_words.py@@ -192,6 +192,11 @@ class AlertWordTests(ZulipTestCase):self.assertFalse(self.message_does_alert(user, "Don't alert on http://t.co/one/ URLs"))self.assertFalse(self.message_does_alert(user, "Don't alert on http://t.co/one URLs"))+ # We don't cause alerts for matches within a word.+ self.assertFalse(+ self.message_does_alert(user, "Don't alert on clone, twofold or seventytwofold")+ )+def test_update_alert_words(self) -> None:user = self.get_user()self.login_user(user)