Skip to content

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

@roysharon

Description

@roysharon

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:'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions