hashchange: Go to home page for bogus narrows.

This was the original intent of the code, and I think
it's the right behavior.
This commit is contained in:
Steve Howell 2018-12-04 22:29:43 +00:00 committed by Tim Abbott
parent bcb142e68e
commit 67fba69b0c
3 changed files with 19 additions and 18 deletions

View File

@ -69,10 +69,9 @@ run_test('test_parse_narrow', () => {
[{negated: false, operator: 'stream', operand: '11-social'}]
);
// This should probably return undefined.
assert.deepEqual(
assert.equal(
hash_util.parse_narrow(['narrow', 'BOGUS']),
[{negated: false, operator: 'BOGUS', operand: ''}]
undefined
);
});

View File

@ -133,23 +133,25 @@ exports.parse_narrow = function (hash) {
for (i = 1; i < hash.length; i += 2) {
// We don't construct URLs with an odd number of components,
// but the user might write one.
try {
var operator = exports.decodeHashComponent(hash[i]);
// Do not parse further if empty operator encountered.
if (operator === '') {
break;
}
var operator = exports.decodeHashComponent(hash[i]);
// Do not parse further if empty operator encountered.
if (operator === '') {
break;
}
var operand = exports.decode_operand(operator, hash[i + 1] || '');
var negated = false;
if (operator[0] === '-') {
negated = true;
operator = operator.slice(1);
}
operators.push({negated: negated, operator: operator, operand: operand});
} catch (err) {
var raw_operand = hash[i + 1];
if (!raw_operand) {
return;
}
var operand = exports.decode_operand(operator, raw_operand);
var negated = false;
if (operator[0] === '-') {
negated = true;
operator = operator.slice(1);
}
operators.push({negated: negated, operator: operator, operand: operand});
}
return operators;
};

View File

@ -44,7 +44,7 @@ enforce_fully_covered = {
'static/js/fenced_code.js',
'static/js/fetch_status.js',
'static/js/filter.js',
# 'static/js/hash_util.js',
'static/js/hash_util.js',
'static/js/keydown_util.js',
'static/js/input_pill.js',
'static/js/list_cursor.js',