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
This commit is contained in:
Aditya Kumar Kasaudhan 2024-10-03 14:36:30 +05:30 committed by Tim Abbott
parent cf879a5f48
commit 8994266137
2 changed files with 45 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
});