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: Validate and parse sender:me when turning into a pill.

evykassirer08ed63976323
diff --git a/web/src/filter.ts b/web/src/filter.ts
index a37ad22d3be..34e87620bf2 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -453,7 +453,7 @@ export class Filter {
}
// Parse a string into a list of terms (see below).
- static parse(str: string): NarrowTerm[] {
+ static parse(str: string, for_pills = false): NarrowTerm[] {
const terms: NarrowTerm[] = [];
let search_term: string[] = [];
let negated;
@@ -511,6 +511,14 @@ export class Filter {
}
}
+ if (
+ for_pills &&
+ operator === "sender" &&
+ operand.toString().toLowerCase() === "me"
+ ) {
+ operand = people.my_current_email();
+ }
+
// We use Filter.operator_to_prefix() to check if the
// operator is known. If it is not known, then we treat
// it as a search for the given string (which may contain
@@ -575,6 +583,9 @@ export class Filter {
case "pm-with":
case "dm-including":
case "pm-including":
+ if (term.operand === "me") {
+ return true;
+ }
return term.operand
.split(",")
.every((email) => people.get_by_email(email) !== undefined);
diff --git a/web/src/search.ts b/web/src/search.ts
index 794cccfc818..f60f9907542 100644
--- a/web/src/search.ts
+++ b/web/src/search.ts
@@ -53,7 +53,7 @@ function full_search_query_in_terms(): NarrowTerm[] {
assert(search_pill_widget !== null);
return [
...search_pill.get_current_search_pill_terms(search_pill_widget),
- ...Filter.parse(get_search_bar_text()),
+ ...Filter.parse(get_search_bar_text(), true),
];
}
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 8eb94deaa21..bca8c791273 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -1405,8 +1405,8 @@ test("parse", () => {
let string;
let terms;
- function _test() {
- const result = Filter.parse(string);
+ function _test(for_pills = false) {
+ const result = Filter.parse(string, for_pills);
assert_same_terms(result, terms);
}
@@ -1444,6 +1444,14 @@ test("parse", () => {
terms = [{operator: "sender", operand: "[email protected]"}];
_test();
+ string = "sender:me";
+ terms = [{operator: "sender", operand: `${me.email}`}];
+ _test(true);
+
+ string = "-sender:me";
+ terms = [{operator: "sender", operand: `${me.email}`, negated: true}];
+ _test(true);
+
string = "https://www.google.com";
terms = [{operator: "search", operand: "https://www.google.com"}];
_test();
@@ -1964,6 +1972,7 @@ test("is_valid_search_term", () => {
["topic:GhostTown", true],
["dm-including:[email protected]", true],
["sender:[email protected]", false],
+ ["sender:me", true],
];