nepsilon / search-query-parser

A simple parser for advanced search query syntax
https://www.npmjs.org/package/search-query-parser
MIT License
253 stars 40 forks source link

Comma should be ignored inside quoted text #16

Closed bradvogel closed 7 years ago

bradvogel commented 7 years ago

The example: require('search-query-parser').parse('test from:"one,two"',{keywords: ['from']}) returns two values, eg from: [ 'one', 'two' ],

I'd think "one,two" should be treated as one word, so it should return from: [ 'one,two' ],

nepsilon commented 7 years ago

I think the current output is the most expected. The comma is an item delimiter.

To make it work the way you want we could escape the comma (either programmatically or by telling the user):

require('search-query-parser').parse('test from:"one\,two"', {keywords: ['from']})
bradvogel commented 7 years ago

It seems clearer to me that anything inside of quotes is automatically escaped (except other quotes of course). So double quotes always have precedence.

So the following would the true: from:one,two -> from: ["one", "two"] from:one\,two -> from: ["one,two"] from:"one,two" -> from: ["one,two"] from:"one\,two" -> from: ["one,two"]

bradvogel commented 7 years ago

Here's a PR: https://github.com/nepsilon/search-query-parser/pull/17

nepsilon commented 7 years ago

That works too. We can use the quotes to mean "one item" and the comma as a separator. We'd need exhaustive test coverage for this though. Let's follow up on the PR.

And thanks for the PR 👍

bradvogel commented 7 years ago

fyi, we just released https://github.com/mixmaxhq/search-string that fixes this