-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
querystring.stringify
unexpected behavior on undefined
values
#28916
Comments
querystring.stringify
unexpected behavior on undefined
querystring.stringify
unexpected behavior on undefined
values
FWIW, this (what I consider to be) confusing behavior has been brought up for years - nodejs/node-v0.x-archive#7971, nodejs/node-v0.x-archive#8825, etc. I think at this point, we are stuck with the behavior. I had proposed nodejs/node-v0.x-archive#8829 a long time ago to try to work around it in a non-breaking way. It might be worth revisiting, although I'd have to look into whether it was still relevant 5 years later 😄 |
@devsnek putting |
I would say so. I believe the current behavior goes all the way back to Node.js v0.1.x. Any change would almost certainly result in ecosystem breakage. It might be good to document it though. I'll add labels. @moshest You want to send a pull request? |
Where are the docs? |
@moshest |
Related to issue nodejs#28916
Done. |
If anyone needs way to filter empty values (including empty strings): // replace queries like "a=1&b=&c=2&d=" to "a=1&c=2"
stringify(query).replace(/&[^=&]+=(?=&|$)/g, '') |
JSON.stringify
omitting undefined values:But
querystring.stringify
not omitting undefined values:Moreover, I think that treating
null
s andundefined
s the same way is less usable for the user (ie. user musts todelete
properties from the object in order to filter them).The text was updated successfully, but these errors were encountered: