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);