Decode operand in filter.js in operator-aware way

When decoding an operand, a + can be converted to a space
only if the operand is not an email address.

(imported from commit 08fc36a579bbe6409137c60c0fa9579fe3ab2c43)
This commit is contained in:
Leo Franchi 2013-10-02 12:08:46 -04:00
parent 8a1b904a2d
commit 0d6ad56c29
2 changed files with 18 additions and 3 deletions

View File

@ -97,8 +97,11 @@ function encodeOperand(operand) {
.replace(/ /g, '+');
}
function decodeOperand(encoded) {
return util.robust_uri_decode(encoded.replace(/\+/g, ' '));
function decodeOperand(encoded, operator) {
if (operator !== 'pm-with' && operator !== 'sender') {
encoded = encoded.replace(/\+/g, ' ');
}
return util.robust_uri_decode(encoded);
}
// Parse a string into a list of operators (see below).
@ -119,7 +122,7 @@ Filter.parse = function (str) {
// Looks like an operator.
// FIXME: Should we skip unknown operator names here?
operator = parts.shift();
operators.push([operator, decodeOperand(parts.join(':'))]);
operators.push([operator, decodeOperand(parts.join(':'), operator)]);
}
});
// NB: Callers of 'parse' can assume that the 'search' operator is last.

View File

@ -177,6 +177,18 @@ function get_predicate(operators) {
string = 'stream:Foo topic:Bar yo';
assert.deepEqual(Filter.unparse(operators), string);
string = 'pm-with:leo+test@zulip.com';
operators = [['pm-with', 'leo+test@zulip.com']];
assert.deepEqual(Filter.parse(string), operators);
string = 'sender:leo+test@zulip.com';
operators = [['sender', 'leo+test@zulip.com']];
assert.deepEqual(Filter.parse(string), operators);
string = 'stream:With+Space';
operators = [['stream', 'With Space']];
assert.deepEqual(Filter.parse(string), operators);
operators = [['id', 50]];
string = 'id:50';
assert.deepEqual(Filter.unparse(operators), string);