mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
This commit prefixes stream names in urls with stream ids, so that the urls don't break when we rename streams. strean name: foo bar.com% before: #narrow/stream/foo.20bar.2Ecom.25 after: #narrow/stream/20-foo-bar.2Ecom.25 For new realms, everything is simple under the new scheme, since we just parse out the stream id every time to figure out where to narrow. For old realms, any old URLs will still work under the new scheme, assuming the stream hasn't been renamed (and of course old urls wouldn't have survived stream renaming in the first place). The one exception is the hopefully rare case of a stream name starting with something like "99-" and colliding with another stream whose id is 99. The way that we enocde the stream name portion of the URL is kind of unimportant now, since we really only look at the stream id, but we still want a safe encoding of the name that is mostly human readable, so we now convert spaces to dashes in the stream name. Also, we try to ensure more code on both sides (frontend and backend) calls common functions to do the encoding. Fixes #4713
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
var hash_util = (function () {
|
|
|
|
var exports = {};
|
|
|
|
// Some browsers zealously URI-decode the contents of
|
|
// window.location.hash. So we hide our URI-encoding
|
|
// by replacing % with . (like MediaWiki).
|
|
exports.encodeHashComponent = function (str) {
|
|
return encodeURIComponent(str)
|
|
.replace(/\./g, '%2E')
|
|
.replace(/%/g, '.');
|
|
};
|
|
|
|
exports.encode_operand = function (operator, operand) {
|
|
if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) {
|
|
var slug = people.emails_to_slug(operand);
|
|
if (slug) {
|
|
return slug;
|
|
}
|
|
}
|
|
|
|
if ((operator === 'stream')) {
|
|
return exports.encode_stream_name(operand);
|
|
}
|
|
|
|
return exports.encodeHashComponent(operand);
|
|
};
|
|
|
|
exports.encode_stream_name = function (operand) {
|
|
// stream_data prefixes the stream id, but it does not do the
|
|
// URI encoding piece
|
|
operand = stream_data.name_to_slug(operand);
|
|
|
|
return exports.encodeHashComponent(operand);
|
|
};
|
|
|
|
exports.decodeHashComponent = function (str) {
|
|
return decodeURIComponent(str.replace(/\./g, '%'));
|
|
};
|
|
|
|
exports.decode_operand = function (operator, operand) {
|
|
if ((operator === 'group-pm-with') || (operator === 'pm-with') || (operator === 'sender')) {
|
|
var emails = people.slug_to_emails(operand);
|
|
if (emails) {
|
|
return emails;
|
|
}
|
|
}
|
|
|
|
operand = exports.decodeHashComponent(operand);
|
|
|
|
if (operator === 'stream') {
|
|
return stream_data.slug_to_name(operand);
|
|
}
|
|
|
|
return operand;
|
|
};
|
|
|
|
return exports;
|
|
|
|
}());
|
|
if (typeof module !== 'undefined') {
|
|
module.exports = hash_util;
|
|
}
|