Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Fix opening compose box when viewing invalid stream.
Tim Abbott3876171df1df
diff --git a/web/src/narrow_state.js b/web/src/narrow_state.jsindex 5daec76896e..a1e8bc7a1d6 100644--- a/web/src/narrow_state.js+++ b/web/src/narrow_state.js@@ -88,7 +88,13 @@ export function set_compose_defaults() {// if they are uniquely specified in the narrow view.if (single.has("stream")) {- opts.stream = stream_data.get_name(single.get("stream"));+ // The raw stream name from collect_single may be an arbitrary+ // unvalidated string from the URL fragment and thus not be valid.+ // So we look up the resolved stream and return that if appropriate.+ const sub = stream_sub();+ if (sub !== undefined) {+ opts.stream = sub.name;+ }}if (single.has("topic")) {diff --git a/web/tests/narrow_state.test.js b/web/tests/narrow_state.test.jsindex e78e37ef894..12b62920bbd 100644--- a/web/tests/narrow_state.test.js+++ b/web/tests/narrow_state.test.js@@ -174,7 +174,14 @@ test("set_compose_defaults", () => {["topic", "Bar"],]);- const stream_and_topic = narrow_state.set_compose_defaults();+ // First try with a stream that doesn't exist.+ let stream_and_topic = narrow_state.set_compose_defaults();+ assert.equal(stream_and_topic.stream, undefined);+ assert.equal(stream_and_topic.topic, "Bar");++ const test_stream = {name: "Foo", stream_id: 72};+ stream_data.add_sub(test_stream);+ stream_and_topic = narrow_state.set_compose_defaults();assert.equal(stream_and_topic.stream, "Foo");assert.equal(stream_and_topic.topic, "Bar");