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: Mark empty user terms as invalid.

Aman Agrawald990e246429b
diff --git a/web/src/filter.ts b/web/src/filter.ts
index d7c46ffacd3..47ebe03ccc2 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -474,6 +474,18 @@ export class Filter {
// NOTE: We will add more logic here once `NarrowTerm`
// operand has different type based on operator.
try {
+ switch (suggestion.operator) {
+ case "dm":
+ case "dm-including":
+ case "sender":
+ // Empty operand is invalid for these operators.
+ // Added here instead of `is_valid_canonical_term`
+ // to create better diffs for future refactoring.
+ if (suggestion.operand === "") {
+ return undefined;
+ }
+ }
+
const potential_narrow_term: NarrowCanonicalTerm = Filter.canonicalize_term(suggestion);
if (!Filter.is_valid_canonical_term(potential_narrow_term)) {
diff --git a/web/src/search_pill.ts b/web/src/search_pill.ts
index db78787622b..f59a628d240 100644
--- a/web/src/search_pill.ts
+++ b/web/src/search_pill.ts
@@ -380,18 +380,17 @@ export function set_search_bar_contents(
switch (term.operator) {
case "dm":
case "dm-including":
- case "sender":
- if (term.operand !== "") {
- const users = term.operand.split(",").map((email) => {
- // This is definitely not undefined, because we just validated it
- // with `Filter.is_valid_search_term`.
- const user = people.get_by_email(email)!;
- return user;
- });
- append_user_pill(users, pill_widget, term.operator, term.negated ?? false);
- added_pills_as_input_strings.add(input);
- }
+ case "sender": {
+ const users = term.operand.split(",").map((email) => {
+ // This is definitely not undefined, because we just validated it
+ // with `Filter.is_valid_search_term`.
+ const user = people.get_by_email(email)!;
+ return user;
+ });
+ append_user_pill(users, pill_widget, term.operator, term.negated ?? false);
+ added_pills_as_input_strings.add(input);
break;
+ }
case "search":
// This isn't a pill, so we don't add it to `added_pills_as_input_strings`
search_operator_strings.push(input);