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.

urls: Support simple integer stream slugs.

Steve Howell2574efde3d8b
diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js
index cae937d05f4..5cf005b622b 100644
--- a/frontend_tests/node_tests/stream_data.js
+++ b/frontend_tests/node_tests/stream_data.js
@@ -103,6 +103,12 @@ run_test('basics', () => {
assert(stream_data.is_default_stream_id(denmark.stream_id));
assert(!stream_data.is_default_stream_id(social.stream_id));
assert(!stream_data.is_default_stream_id(999999));
+
+ assert.equal(stream_data.slug_to_name('2-social'), 'social');
+ assert.equal(stream_data.slug_to_name('2-whatever'), 'social');
+ assert.equal(stream_data.slug_to_name('2'), 'social');
+
+ assert.equal(stream_data.slug_to_name('25-or-6-to-4'), '25-or-6-to-4');
});
run_test('renames', () => {
diff --git a/static/js/stream_data.js b/static/js/stream_data.js
index 6ea06448d7b..7e6629aa866 100644
--- a/static/js/stream_data.js
+++ b/static/js/stream_data.js
@@ -258,7 +258,35 @@ exports.name_to_slug = function (name) {
};
exports.slug_to_name = function (slug) {
- const m = /^([\d]+)-/.exec(slug);
+ /*
+ Modern stream slugs look like this, where 42
+ is a stream id:
+
+ 42
+ 42-stream-name
+
+ We have legacy slugs that are just the name
+ of the stream:
+
+ stream-name
+
+ And it's plausible that old stream slugs will have
+ be based on stream names that collide with modern
+ slugs:
+
+ 4-horseman
+ 411
+ 2016-election
+
+ If there is any ambiguity about whether a stream slug
+ is old or modern, we prefer modern, as long as the integer
+ prefix matches a real stream id. Eventually we will
+ stop supporting the legacy slugs, which only matter now
+ because people have linked to Zulip threads in things like
+ GitHub conversations. We migrated to modern slugs in
+ early 2018.
+ */
+ const m = /^([\d]+)(-.*)?/.exec(slug);
if (m) {
const stream_id = parseInt(m[1], 10);
const sub = subs_by_stream_id.get(stream_id);
@@ -270,6 +298,10 @@ exports.slug_to_name = function (slug) {
// link to a stream like 4-horsemen
}
+ /*
+ We are dealing with a pre-2018 slug that doesn't have the
+ stream id as a prefix.
+ */
return slug;
};