Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

narrow: Handle narrow links with empty topic names.

Prakhar Pratyush53ba17e1e0d4
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index 5a1ba3b612a..7e00f617fdc 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -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});
}
diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjs
index 852b5f0e2f7..5031b3e75f2 100644
--- a/web/tests/hash_util.test.cjs
+++ b/web/tests/hash_util.test.cjs
@@ -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", () => {