From 89942661370949627aebef9524f436bc61dba8b4 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Kasaudhan Date: Thu, 3 Oct 2024 14:36:30 +0530 Subject: [PATCH] left-sidebar: Use -, _, :, and / as additional topic word separators. Previously, only spaces were used as word separators when searching for topics. This meant that searching for "support" would not find a topic named "topic_support" or "topic/support," which could lead to unexpected results. To address this, hyphen (-), underscore (_), colon (:), and slash (/) have been added as additional word separators for topic filtering in the left sidebar, as these characters are commonly used as separators in topic names. Fixes: #31844 --- web/src/topic_list_data.ts | 8 ++++++- web/tests/topic_list_data.test.js | 38 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.ts index afc7cd6c79..e0352a744c 100644 --- a/web/src/topic_list_data.ts +++ b/web/src/topic_list_data.ts @@ -187,7 +187,13 @@ export function get_list_info( } if (zoomed) { - topic_names = util.filter_by_word_prefix_match(topic_names, search_term, (item) => item); + const word_separator_regex = /[\s/:_-]/; // Use -, _, :, / as word separators in addition to spaces. + topic_names = util.filter_by_word_prefix_match( + topic_names, + search_term, + (topic) => topic, + word_separator_regex, + ); } if (stream_muted && !zoomed) { diff --git a/web/tests/topic_list_data.test.js b/web/tests/topic_list_data.test.js index aecbc330f6..3a897bceed 100644 --- a/web/tests/topic_list_data.test.js +++ b/web/tests/topic_list_data.test.js @@ -404,3 +404,41 @@ test("get_list_info unreads", ({override}) => { ], ); }); + +test("get_list_info with specific topics and searches", () => { + let list_info; + + function add_topic_message(topic_name, message_id) { + stream_topic_history.add_message({ + stream_id: general.stream_id, + topic_name, + message_id, + }); + } + + add_topic_message("BF-2924 zulip", 1001); + add_topic_message("tech_support/escalation", 1002); + + list_info = get_list_info(true, "2924"); + assert.equal(list_info.items.length, 1); + assert.equal(list_info.items[0].topic_name, "BF-2924 zulip"); + + list_info = get_list_info(true, "support/escalation"); + assert.equal(list_info.items.length, 1); + assert.equal(list_info.items[0].topic_name, "tech_support/escalation"); + + list_info = get_list_info(true, "support"); + assert.equal(list_info.items.length, 1); + assert.equal(list_info.items[0].topic_name, "tech_support/escalation"); + + list_info = get_list_info(true, "zulip"); + assert.equal(list_info.items.length, 1); + assert.equal(list_info.items[0].topic_name, "BF-2924 zulip"); + + list_info = get_list_info(true, "SUPPORT"); + assert.equal(list_info.items.length, 1); + assert.equal(list_info.items[0].topic_name, "tech_support/escalation"); + + list_info = get_list_info(true, "nonexistent"); + assert.equal(list_info.items.length, 0); +});