search: Parse quoted strings as single tokens

(imported from commit 252f2657881ad4184a2564d16bf11558613efead)
This commit is contained in:
Zev Benjamin 2013-05-13 17:35:55 -04:00 committed by Tim Abbott
parent 4bfda4c49e
commit 60e479bdf1
1 changed files with 5 additions and 5 deletions

View File

@ -290,19 +290,19 @@ exports.set_compose_defaults = function (opts) {
exports.parse = function (str) {
var operators = [];
var search_term = [];
$.each(str.split(/ +/), function (idx, token) {
$.each(str.match(/"[^"]+"|\S+/g), function (idx, token) {
var parts, operator;
if (token.length === 0)
return;
parts = token.split(':');
if (parts.length > 1) {
if (token[0] === '"' || parts.length === 1) {
// Looks like a normal search term.
search_term.push(token);
} else {
// Looks like an operator.
// FIXME: Should we skip unknown operator names here?
operator = parts.shift();
operators.push([operator, decodeOperand(parts.join(':'))]);
} else {
// Looks like a normal search term.
search_term.push(token);
}
});
// NB: Callers of 'parse' can assume that the 'search' operator is last.