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-state: Return undefined for a channel ID that would be NaN.

Lauryn Menard61fa5ccbf1c9
diff --git a/web/src/narrow_state.ts b/web/src/narrow_state.ts
index c08f9ff5e1b..f5ee6a12213 100644
--- a/web/src/narrow_state.ts
+++ b/web/src/narrow_state.ts
@@ -130,7 +130,10 @@ export let stream_id = (current_filter: Filter | undefined = filter()): number |
}
const stream_operands = current_filter.operands("channel");
if (stream_operands.length === 1 && stream_operands[0] !== undefined) {
- return Number.parseInt(stream_operands[0], 10);
+ const id = Number.parseInt(stream_operands[0], 10);
+ if (!Number.isNaN(id)) {
+ return id;
+ }
}
return undefined;
};
diff --git a/web/tests/narrow_state.test.cjs b/web/tests/narrow_state.test.cjs
index 42f5d0132c1..feb1a1032b4 100644
--- a/web/tests/narrow_state.test.cjs
+++ b/web/tests/narrow_state.test.cjs
@@ -40,6 +40,15 @@ test("stream", () => {
assert.ok(!narrow_state.filter());
assert.equal(narrow_state.stream_id(), undefined);
+ // hash_util.decode_operand returns an empty string when
+ // stream_data.slug_to_stream_id returns undefined, e.g., the
+ // stream name in the URL no longer exists or is inaccessible.
+ set_filter([["channel", ""]]);
+ assert.ok(narrow_state.filter());
+ assert.equal(narrow_state.stream_name(), undefined);
+ assert.equal(narrow_state.stream_id(), undefined);
+ assert.equal(narrow_state.stream_sub(), undefined);
+
const test_stream_id = 15;
const test_stream = {name: "Test", stream_id: test_stream_id};
stream_data.add_sub(test_stream);