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.

web-hash-util: Decode URL with channel and encoded stream ID.

Lauryn Menard556629add099
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index bb26762cf49..c496d85426b 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -66,7 +66,7 @@ export function decode_operand(operator: string, operand: string): string {
operand = internal_url.decodeHashComponent(operand);
- if (operator === "stream") {
+ if (util.canonicalize_stream_synonyms(operator) === "stream") {
return stream_data.slug_to_name(operand);
}
diff --git a/web/tests/hashchange.test.js b/web/tests/hashchange.test.js
index aed1f4dbcea..47fc62c943e 100644
--- a/web/tests/hashchange.test.js
+++ b/web/tests/hashchange.test.js
@@ -85,6 +85,8 @@ run_test("stream_to_channel_rename", () => {
let narrow;
let filter;
+ // Confirm the URLs generated from search terms use "stream" and "streams"
+ // and that the new Filter has the new "channel" and "channels" operators.
terms = [{operator: "channel", operand: "devel"}];
hash = hash_util.search_terms_to_hash(terms);
assert.equal(hash, "#narrow/stream/devel");
@@ -100,6 +102,19 @@ run_test("stream_to_channel_rename", () => {
assert.deepEqual(narrow, [{operator: "streams", operand: "public", negated: false}]);
filter = new Filter(narrow);
assert.deepEqual(filter.terms(), [{operator: "channels", operand: "public", negated: false}]);
+
+ // Confirm that a narrow URL with "channel" and an enocoded stream/channel ID,
+ // will be decoded correctly.
+ const test_channel = {
+ name: "decode",
+ stream_id: 34,
+ };
+ stream_data.add_sub(test_channel);
+ hash = "#narrow/channel/34-decode";
+ narrow = hash_util.parse_narrow(hash.split("/"));
+ assert.deepEqual(narrow, [{operator: "channel", operand: "decode", negated: false}]);
+ filter = new Filter(narrow);
+ assert.deepEqual(filter.terms(), [{operator: "channel", operand: "decode", negated: false}]);
});
run_test("terms_trailing_slash", () => {