hashchange: Handle trailing slashes in narrowing URLs.

Fixes #9305.
Empty operators are not allowed while parsing narrowing URLs.
`parse_narrow` stops parsing further if it encounters an empty string
operator.
This commit is contained in:
Shubham Padia
2018-05-15 19:29:50 +05:30
committed by Tim Abbott
parent 83ee8211a8
commit f0d874d51f
2 changed files with 17 additions and 0 deletions

View File

@@ -81,6 +81,18 @@ run_test('operators_round_trip', () => {
]);
});
run_test('operators_trailing_slash', () => {
var hash;
var narrow;
hash = '#narrow/stream/devel/topic/algol/';
narrow = hashchange.parse_narrow(hash.split('/'));
assert.deepEqual(narrow, [
{operator: 'stream', operand: 'devel', negated: false},
{operator: 'topic', operand: 'algol', negated: false},
]);
});
run_test('people_slugs', () => {
var operators;
var hash;

View File

@@ -77,6 +77,11 @@ exports.parse_narrow = function (hash) {
// but the user might write one.
try {
var operator = hash_util.decodeHashComponent(hash[i]);
// Do not parse further if empty operator encountered.
if (operator === '') {
break;
}
var operand = hash_util.decode_operand(operator, hash[i+1] || '');
var negated = false;
if (operator[0] === '-') {