From 5a37692e67230315e209bbaabbf29e297cdf4a8a Mon Sep 17 00:00:00 2001 From: Daniel Spofford Date: Mon, 4 May 2015 09:54:17 -0500 Subject: [PATCH] Correctly handle semicolons within search term values --- lib/search-query-parser.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/search-query-parser.js b/lib/search-query-parser.js index f38ffe3..d1f2a4d 100644 --- a/lib/search-query-parser.js +++ b/lib/search-query-parser.js @@ -30,10 +30,11 @@ exports.parse = function (string, options) { // Get a list of search terms respecting single and double quotes var terms = string.match(/(\S+:'(?:[^'\\]|\\.)*')|(\S+:"(?:[^"\\]|\\.)*")|\S+|\S+:\S+/g); for (var i = 0; i < terms.length; i++) { - if(terms[i].indexOf(':') !== -1) { + var sepIndex = terms[i].indexOf(':'); + if(sepIndex !== -1) { var split = terms[i].split(':'), - key = split[0], - val = split[1]; + key = terms[i].slice(0, sepIndex), + val = terms[i].slice(sepIndex + 1); // Strip surrounding quotes val = val.replace(/^\"|\"$|^\'|\'$/g, ''); // Strip backslashes respecting escapes