Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
people: Match a typed user id exactly, not as a prefix.
Shubham Padia145f1d6b65e9
diff --git a/web/src/people.ts b/web/src/people.tsindex cb4730fb5da..4e53135ad47 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -1180,7 +1180,7 @@ export function build_person_matcher(query: string): (user: User) => boolean {const termlet_matchers = termlets.map((termlet) => build_termlet_matcher(termlet));return function (user: User): boolean {- if (String(user.user_id).startsWith(query)) {+ if (String(user.user_id) === query) {return true;}diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjsindex df3523fd89b..bc7b796cf19 100644--- a/web/tests/people.test.cjs+++ b/web/tests/people.test.cjs@@ -225,6 +225,14 @@ const linus = make_user({full_name: "Linus Torvalds",});+// A user whose full name starts with digits, used to verify that+// id matching is exact and does not collide with digit-leading names.+const digit_named = make_user({+ email: "[email protected]",+ user_id: 9001,+ full_name: "304 Robot",+});+const emp401 = make_user({email: "[email protected]",user_id: 401,@@ -871,6 +879,7 @@ run_test("dm_matches_search_string", () => {people.add_active_user(linus);people.add_active_user(noah);people.add_active_user(plain_noah);+ people.add_active_user(digit_named);let result = people.dm_matches_search_string([ashton], "a");assert.ok(result);@@ -894,6 +903,13 @@ run_test("dm_matches_search_string", () => {// Match with user id.result = people.dm_matches_search_string([linus], "304");assert.ok(result);+ result = people.dm_matches_search_string([linus], "30");+ assert.ok(!result);++ // A full name starting with digits is still matched by name, and+ // is not affected by the (unrelated) id of any other user.+ result = people.dm_matches_search_string([digit_named], "304");+ assert.ok(result);// Test filtering of names with diacritics. This should match// Nöôáàh by ignoring diacritics, and also match Nooaah.