Set negated flag explicity to false in JS code.

For negated search terms, we weren't explicitly setting
"negated" to false when callers left it undefined, which was
mostly fine, since undefined is falsey, but it is better to
define it explicitly for debugging/testing purposes.

(imported from commit 68a2790b510d17caed8ca11c38188545d1dcc347)
This commit is contained in:
Steve Howell
2014-02-13 09:32:57 -05:00
parent 2fb7c0059d
commit 76ff3a526c
2 changed files with 15 additions and 2 deletions

View File

@@ -135,6 +135,12 @@ Filter.canonicalize_term = function (opts) {
var operator = opts.operator;
var operand = opts.operand;
// Make negated be explictly false for both clarity and
// simplifying deepEqual checks in the tests.
if (!negated) {
negated = false;
}
if (operator === undefined) {
blueslip.error("Old-style tuple operators are still in use for canonicalize_term");
operator = opts[0];
@@ -237,7 +243,7 @@ Filter.parse = function (str) {
if (search_term.length > 0) {
operator = 'search';
operand = search_term.join(' ');
term = {operator: operator, operand: operand};
term = {operator: operator, operand: operand, negated: false};
operators.push(term);
}
return operators;

View File

@@ -14,8 +14,15 @@ var Filter = require('js/filter.js');
var _ = global._;
function assert_same_operators(result, terms) {
result = _.map(result, function (term) {
terms = _.map(result, function (term) {
// If negated flag is undefined, we explicitly
// set it to false.
var negated = term.negated;
if (!negated) {
negated = false;
}
return {
negated: negated,
operator: term.operator,
operand: term.operand
};