mirror of https://github.com/zulip/zulip.git
search: Parse quoted strings as single tokens
(imported from commit 252f2657881ad4184a2564d16bf11558613efead)
This commit is contained in:
parent
4bfda4c49e
commit
60e479bdf1
|
@ -290,19 +290,19 @@ exports.set_compose_defaults = function (opts) {
|
||||||
exports.parse = function (str) {
|
exports.parse = function (str) {
|
||||||
var operators = [];
|
var operators = [];
|
||||||
var search_term = [];
|
var search_term = [];
|
||||||
$.each(str.split(/ +/), function (idx, token) {
|
$.each(str.match(/"[^"]+"|\S+/g), function (idx, token) {
|
||||||
var parts, operator;
|
var parts, operator;
|
||||||
if (token.length === 0)
|
if (token.length === 0)
|
||||||
return;
|
return;
|
||||||
parts = token.split(':');
|
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.
|
// Looks like an operator.
|
||||||
// FIXME: Should we skip unknown operator names here?
|
// FIXME: Should we skip unknown operator names here?
|
||||||
operator = parts.shift();
|
operator = parts.shift();
|
||||||
operators.push([operator, decodeOperand(parts.join(':'))]);
|
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.
|
// NB: Callers of 'parse' can assume that the 'search' operator is last.
|
||||||
|
|
Loading…
Reference in New Issue