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.

filter: Reject negated id, near, and with terms.

Aman Agrawal597050f39011
diff --git a/web/src/filter.ts b/web/src/filter.ts
index eb8eb54fe11..28f4bdd266e 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -663,6 +663,11 @@ export class Filter {
case "id":
case "near":
case "with":
+ // Negating these doesn't have a useful meaning,
+ // so we reject it (matching `date` below).
+ if (term.negated) {
+ return false;
+ }
return Number.isInteger(Number(term.operand));
case "channel":
return stream_data.get_sub_by_id_string(term.operand) !== undefined;
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index a8f2a8910e7..8aec6492326 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -2326,6 +2326,11 @@ test("convert_suggestion_to_term", () => {
["in:home", true],
["in:nowhere", false],
["id:4", true],
+ ["-id:4", false],
+ ["near:1", true],
+ ["-near:1", false],
+ ["with:1", true],
+ ["-with:1", false],
["near:home", false],
["channel:" + denmark.stream_id, true],
[`channel:${invalid_sub_id}`, false],