query-string icon indicating copy to clipboard operation
query-string copied to clipboard

Lack of symmetry between parse and stringify

Open roberttaylor426 opened this issue 5 years ago • 3 comments

stringify(parse('?%20&')) yields only &.

Bit of an edge-case I admit, but do we want to be losing this information?

parse('?%20&') yields {"":null," ":null}.

roberttaylor426 avatar Nov 10 '20 17:11 roberttaylor426

I think parse('?%20&') should result in {}. Keeping empty keys or whitespace only keys are not useful.

sindresorhus avatar Nov 20 '20 17:11 sindresorhus

I'd be happy to take a look at this.

In my opinion assuming empty or whitespace-only keys are not useful to the client feels a little presumptuous. If someone tries to parse '?%20&', isn't {"":null," ":null} the honest response? (Either that or {"":""," ":""}).

roberttaylor426 avatar Nov 27 '20 18:11 roberttaylor426

I don't think anyone would actually do this in real code though. If you really think it matters, we could document the behavior.

sindresorhus avatar Nov 28 '20 10:11 sindresorhus