You've already forked search-query-parser
Do not split on spaces inside simple and double quotes
Use a regex to identify search terms more reliably than spliting on a space. Does NOT respect escaping simple or double quotes within a term since JS does not support look-behinds in regexs.
This commit is contained in:
@@ -27,8 +27,14 @@ exports.parse = function (string, options) {
|
|||||||
else {
|
else {
|
||||||
// Our object to store the query object
|
// Our object to store the query object
|
||||||
var query = {text: []};
|
var query = {text: []};
|
||||||
// Get a list of search term. Reverse to ensure proper order when pop()'ing.
|
// Get a list of search terms respecting single and double quotes
|
||||||
var terms = string.split(' ').reverse();
|
var terms = string.match(/(\S+:(".+?"|'.+?'))|(\S+:\S+)|\S+/g);
|
||||||
|
// Rip out the quotes
|
||||||
|
for (var i = 0; i < terms.length; i++) {
|
||||||
|
terms[i] = terms[i].replace(/['"]+/g, '');
|
||||||
|
};
|
||||||
|
// Reverse to ensure proper order when pop()'ing.
|
||||||
|
terms.reverse();
|
||||||
// For each search term
|
// For each search term
|
||||||
while (term = terms.pop()) {
|
while (term = terms.pop()) {
|
||||||
// Advanced search terms syntax has key and value
|
// Advanced search terms syntax has key and value
|
||||||
|
|||||||
Reference in New Issue
Block a user