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.

search: Remove unreachable email validation in person operand check.

Shubham Padiad31df5ba9a5c
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 4f67a273fed..2581fb13bff 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -1117,25 +1117,22 @@ export let get_suggestions = function (
// Handle spaces in person name in new suggestions only. Checks if the last operator is 'search'
// and the second last operator in search_terms is one out of person_suggestion_ops.
// e.g for `sender:Ted sm`, initially last = {operator: 'search', operand: 'sm'....}
- // and second last is {operator: 'sender', operand: 'sm'....}. If the second last operand
- // is an email of a user, both of these terms remain unchanged. Otherwise search operator
- // will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}.
+ // and second last is {operator: 'sender', operand: 'Ted'....}. The search operator
+ // will be deleted and new last will become {operator:'sender', operand: 'Ted sm'....}.
if (
text_search_terms.length > 1 &&
last.operator === "search" &&
person_suggestion_ops.includes(text_search_terms.at(-2)!.operator)
) {
const person_op = text_search_terms.at(-2)!;
- if (!people.reply_to_to_user_ids_string(person_op.operand)) {
- last = {
- operator: person_op.operator,
- operand: person_op.operand + " " + last.operand,
- negated: person_op.negated,
- };
- text_search_terms.splice(-2);
- text_search_terms.push(last);
- all_search_terms = [...pill_search_terms, ...text_search_terms];
- }
+ last = {
+ operator: person_op.operator,
+ operand: person_op.operand + " " + last.operand,
+ negated: person_op.negated,
+ };
+ text_search_terms.splice(-2);
+ text_search_terms.push(last);
+ all_search_terms = [...pill_search_terms, ...text_search_terms];
}
const valid_base_text_search_terms = text_search_terms
.slice(0, -1)
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index b18457ab67d..ace627432a3 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -1032,13 +1032,17 @@ test("people_suggestions", ({override}) => {
suggestions = get_suggestions(query);
assert.deepEqual(suggestions, expected);
+ // The search bar typeahead always converts person operators to
+ // user_id-based pills, so raw email operands are not reachable.
+ // Both valid and invalid emails get merged with the trailing
+ // search term, producing no person match.
query = "sender:[email protected] new";
- expected = ["new"];
+ expected = [];
suggestions = get_suggestions(query);
assert.deepEqual(suggestions, expected);
query = "sender:[email protected] new";
- expected = []; // Invalid email
+ expected = [];
suggestions = get_suggestions(query);
assert.deepEqual(suggestions, expected);
});