Prevent browser errors for stream: searches.

When we typed "stream:" into the search bar, the empty operand
triggered an error in the Dict class for an undefined key, because
we were using opts[0] as a "defensive" workaround to opts.operand,
but opts.operand of '' is more correct than opts[0] being undefined.

Now we only fall back to opts[0] whe opts.operand is undefined, and
we emit a blueslip error when that happens.

(imported from commit 88a196d3bc3d67689c36bc036f378da744c652f9)
This commit is contained in:
Steve Howell 2014-02-10 13:09:16 -05:00
parent 10b24f77b6
commit 6b93315cc3
2 changed files with 18 additions and 5 deletions

View File

@ -151,9 +151,14 @@ Filter.canonicalize_operator = function (operator) {
};
Filter.canonicalize_term = function (opts) {
// Legacy code may still call use with a tuple of [operator, operand].
var operator = opts.operator || opts[0];
var operand = opts.operand || opts[1];
var operator = opts.operator;
var operand = opts.operand;
if (operator === undefined) {
blueslip.error("Old-style tuple operators are still in use for canonicalize_term");
operator = opts[0];
operand = opts[1];
}
operator = Filter.canonicalize_operator(operator);

View File

@ -187,11 +187,19 @@ function get_predicate(operators) {
assert(predicate({type: 'stream', stream: 'foo', subject: 'bar.d'}));
// Try to get the MIT regex to explode for an empty stream.
predicate = new Filter([['stream', ''], ['topic', 'bar']]).predicate();
var terms = [
{operator: 'stream', operand: ''},
{operator: 'topic', operand: 'bar'}
];
predicate = new Filter(terms).predicate();
assert(!predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
// Try to get the MIT regex to explode for an empty topic.
predicate = new Filter([['stream', 'foo'], ['topic', '']]).predicate();
terms = [
{operator: 'stream', operand: 'foo'},
{operator: 'topic', operand: ''}
];
predicate = new Filter(terms).predicate();
assert(!predicate({type: 'stream', stream: 'foo', subject: 'bar'}));
}());