Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

alert_words: Highlight overlapping alert words more accurately.

shashank-23002b74dabfaa41e
diff --git a/web/src/alert_words.ts b/web/src/alert_words.ts
index 6b192452579..971bc878089 100644
--- a/web/src/alert_words.ts
+++ b/web/src/alert_words.ts
@@ -8,7 +8,12 @@ import * as people from "./people";
let my_alert_words: string[] = [];
export function set_words(words: string[]): void {
+ // This module's highlighting algorithm of greedily created
+ // highlight spans cannot correctly handle overlapping alert word
+ // clauses, but processing in order from longest-to-shortest
+ // reduces some symptoms of this. See #28415 for details.
my_alert_words = words;
+ my_alert_words.sort((a, b) => b.length - a.length);
}
export function get_word_list(): {word: string}[] {
diff --git a/web/tests/alert_words.test.js b/web/tests/alert_words.test.js
index 094124bb03f..749ca1c635f 100644
--- a/web/tests/alert_words.test.js
+++ b/web/tests/alert_words.test.js
@@ -116,7 +116,18 @@ run_test("notifications", () => {
run_test("munging", () => {
alert_words.initialize(params);
-
+ assert.deepEqual(alert_words.get_word_list(), [
+ {word: "alertthree"},
+ {word: "alertone"},
+ {word: "alerttwo"},
+ {word: "al*rt.*s"},
+ {word: "emoji"},
+ {word: `5'11"`},
+ {word: "FD&C"},
+ {word: ".+"},
+ {word: "<3"},
+ {word: ">8"},
+ ]);
let saved_content = regular_message.content;
alert_words.process_message(regular_message);
assert.equal(saved_content, regular_message.content);
diff --git a/web/tests/dispatch.test.js b/web/tests/dispatch.test.js
index bd3b03288b6..a83b36128d1 100644
--- a/web/tests/dispatch.test.js
+++ b/web/tests/dispatch.test.js
@@ -160,7 +160,7 @@ run_test("alert_words", ({override}) => {
const event = event_fixtures.alert_words;
dispatch(event);
- assert.deepEqual(alert_words.get_word_list(), [{word: "fire"}, {word: "lunch"}]);
+ assert.deepEqual(alert_words.get_word_list(), [{word: "lunch"}, {word: "fire"}]);
assert.ok(alert_words.has_alert_word("fire"));
assert.ok(alert_words.has_alert_word("lunch"));
});