question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

qs.parse omitting empty string keys

See original GitHub issue

Hi, it will be nice to have this part configurable:

https://github.com/ljharb/qs/blob/542a5c7ff88d7229efa2e22c7c8a7d69375f5e72/lib/parse.js#L150-L152

current output:

qs.parse("=1&=2") === {}
qs.parse(" =1& =2") === { " ": ["1","2"] }

expected output :

qs.parse("=1&=2", { allowEmptyKeys: true }) === { "": ["1","2"] }

If you are ok - I can open a PR

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Mar 3, 2022

“USP supports it” is a good argument, although your use cases are not convincing - if the key’s not present yet, then the value isn’t either, and I’m not clear on why the key would really evaluate to an empty string.

The PR adding this would have to add it to both parse and stringify, so that there could be a round trip.

Additionally, what happens with =1&=2, in the arrayFormat repeat vs brackets? What about []=1&[]=2?

0reactions
Coobahacommented, Mar 5, 2022

@ljharb opened #433 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove keys with empty or null values in qs.stringify when ...
You can make a function using Object.fromEntries and Object.entries to filter out non-null and non-empty values:
Read more >
Option to preserve empty arrays and objects at "qs.stringify()"
I'm trying to persist query string which contains complex JSON structure on page refresh. This is why inconsistency matters for my case.
Read more >
294fa139fae33e2a5ad12badf4d...
qs. A querystring parsing and stringifying library with some added security. ... Empty strings and null values will omit the value, but the...
Read more >
Reference - Nginx.org
More advanced parsing scenarios can be achieved with the Query String module and with the $args variable, for example: import qs from 'querystring'; ......
Read more >
Issues · ljharb/qs · GitHub
qs.parse (with allowDots) provided with the same key object and strings gives varying results bug parse. #122 opened on Oct 19, 2015 by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found