mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
narrow: Handle narrow links with empty topic names.
This commit ensures that narrow links involving empty topic names, such as: * #narrow/channel/1-general/topic//near/12345 * #narrow/channel/1-general/topic/ work correctly in the web client. This change ensures proper navigation and behavior for such links.
This commit is contained in:
committed by
Tim Abbott
parent
de78864b8c
commit
53ba17e1e0
@@ -173,7 +173,7 @@ export function parse_narrow(hash: string[]): NarrowTerm[] | undefined {
|
||||
|
||||
const raw_operand = hash[i + 1];
|
||||
|
||||
if (!raw_operand) {
|
||||
if (raw_operand === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -183,6 +183,12 @@ export function parse_narrow(hash: string[]): NarrowTerm[] | undefined {
|
||||
operator = operator.slice(1);
|
||||
}
|
||||
|
||||
// We allow the empty string as a topic name.
|
||||
// Any other operand being empty string is invalid.
|
||||
if (operator !== "topic" && raw_operand === "") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const operand = decode_operand(operator, raw_operand);
|
||||
terms.push({negated, operator, operand});
|
||||
}
|
||||
|
||||
@@ -190,6 +190,18 @@ run_test("test_parse_narrow", () => {
|
||||
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "42-bogus"]), [
|
||||
{negated: false, operator: "stream", operand: ""},
|
||||
]);
|
||||
|
||||
// Empty string as a topic name is valid.
|
||||
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend", "topic", ""]), [
|
||||
{negated: false, operator: "stream", operand: frontend_id.toString()},
|
||||
{negated: false, operator: "topic", operand: ""},
|
||||
]);
|
||||
|
||||
// Empty string used as an operand in other cases is invalid.
|
||||
assert.deepEqual(
|
||||
hash_util.parse_narrow(["narrow", "stream", "99-frontend", "topic", "", "near", ""]),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
|
||||
run_test("test_channels_settings_edit_url", () => {
|
||||
|
||||
Reference in New Issue
Block a user