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

Parse/stringify mismatch when using a keyword with an empty value #56

Open roysharon opened 11 months ago

roysharon commented 11 months ago

When using a string including a keyword with an empty value, calling parse and then stringify produces an empty string:

import parser from 'search-query-parser' 

const orgStringified = 'brakes:'
const options = { keywords: ['brakes'], offsets: false }
const query = parser.parse(orgStringified, options)
// query = { exclude: {} }
const destStringified = parser.stringify(query, options)
// destStringified = ''

What I would expect is that the result of parse would include the keyword but with an undefined value, and then stringify can produce the original input:


const expectedQuery = parser.parse(orgStringified, options)
// expectedQuery = { brakes: undefined, exclude: {} }
const expectedDestStringified = parser.stringify(expectedQuery, options)
// expectedDestStringified = 'brakes:'