Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_util: Fix "Invalid URL" for unparsable sender and mentions IDs.
Aman Agrawal5de47e5df357
diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex ae54f2c7749..d4715d51c04 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -87,8 +87,8 @@ export function decode_operand(} else if (operator === "dm-including" || operator === "dm") {return decode_user_ids(operand);} else if (operator === "sender" || operator === "mentions") {- const user_ids = people.slug_to_user_ids(operand);- if (user_ids?.length !== 1) {+ const user_ids = decode_user_ids(operand);+ if (user_ids.length !== 1) {// User mistyped the URL since we don't support// group operand for `sender` or `mentions` narrow.// Returning UNKNOWN_USER_ID will lead to us showing a properdiff --git a/web/src/people.ts b/web/src/people.tsindex c309931bff0..ee51de9bf9e 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -622,44 +622,6 @@ export function user_ids_string_to_slug(user_ids_string: string): string {return user_ids_to_slug(user_ids);}-export function slug_to_user_ids(slug: string): number[] | undefined {- /*- It's not super important to be flexible about- direct message related slugs, since you would- rarely post them to the web, but we do want- to support reasonable variations:-- 99-- Our canonical version is [email protected],- and we only care about the "99" prefix.- */- const m = /^([\d,]+)(-.*)?/.exec(slug);- if (m) {- const user_ids_string = m[1]!;- return exclude_me_from_user_ids(split_to_ints(user_ids_string));- }- /* istanbul ignore next */- return undefined;-}--export function exclude_me_from_user_ids(user_ids: number[]): number[] {- // Exclude me from a user_ids_string UNLESS I'm the- // only one in it.-- if (user_ids.length <= 1) {- // We either have a message to ourself, an empty- // slug, or a message to somebody else where we weren't- // part of the slug.- return user_ids;- }-- user_ids = user_ids.filter((user_id) => !is_my_user_id(user_id));-- return user_ids;-}-export function sender_is_bot(message: Message): boolean {if (message.sender_id) {const person = get_by_user_id(message.sender_id);diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjsindex d944ba43d36..1016f77ca97 100644--- a/web/tests/hash_util.test.cjs+++ b/web/tests/hash_util.test.cjs@@ -267,6 +267,20 @@ run_test("parse_narrow_user_slug", () => {assert.deepEqual(parsed_operand(operator, `15,${id}`), [UNKNOWN_USER_ID, 15]);}}++ for (const operator of ["sender", "mentions"]) {+ assert.equal(parsed_operand(operator, "15-Smith,-John"), 15);+ assert.equal(parsed_operand(operator, "15,15"), 15);+ assert.equal(parsed_operand(operator, "[email protected]"), UNKNOWN_USER_ID);+ assert.equal(parsed_operand(operator, "[email protected]"), UNKNOWN_USER_ID);+ for (const id of ids_above_max_safe_integer) {+ assert.equal(parsed_operand(operator, id), UNKNOWN_USER_ID);+ }+ // These operators take one user.+ assert.equal(parsed_operand(operator, "15,16-group"), UNKNOWN_USER_ID);+ // The current user is dropped from a list, leaving the invalid member.+ assert.equal(parsed_operand(operator, `${me.user_id},invalid`), UNKNOWN_USER_ID);+ }});run_test("test_channels_settings_edit_url", () => {diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjsindex 034389616e6..12363c76e45 100644--- a/web/tests/people.test.cjs+++ b/web/tests/people.test.cjs@@ -977,12 +977,6 @@ run_test("multi_user_methods", () => {assert.equal(emp401.user_id, 401);assert.equal(emp402.user_id, 402);- let user_ids = people.slug_to_user_ids("402,401");- assert.deepEqual(user_ids, [402, 401]);-- user_ids = people.slug_to_user_ids("402,401-group");- assert.deepEqual(user_ids, [402, 401]);-assert.equal(people.user_ids_string_to_slug("401,402"), "401,402-group");assert.equal(people.user_ids_string_to_slug("402"), "402-whatever-402");assert.equal(people.user_ids_to_slug([401, 402]), "401,402-group");