Skip to content
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

QueryStringAddon converts undefined values into empty strings instead of omitting them #229

Closed
dankochetov opened this issue May 10, 2024 · 2 comments · Fixed by #230
Closed

Comments

@dankochetov
Copy link
Contributor

For a query like this

wretch('https://example.com').addon(QueryStringAddon).query({ bar: 'qwe', foo: undefined }).post().json();

The produced URL is https://example.com?bar=qwe&foo= instead of https://example.com?bar=qwe

@dankochetov
Copy link
Contributor Author

I checked the source code and saw the stringify function implementation that specifically converts undefined to an empty string, but IMO that's a misleading and dangerous behavior (at least for me, coming from axios, which removes keys with undefined values from the query string). I think it's a common pattern to pass optional query params to a request like that.
Does it make sense to omit null and undefined values from the result? I can make a PR with this change. In fact, I've already done it since it's a one line change, feel free to close it if you disagree that it should work like that.

@elbywan
Copy link
Owner

elbywan commented May 11, 2024

Hey @dankochetov,

Does it make sense to omit null and undefined values from the result? I can make a PR with this change.

Thanks for the PR! I'm fine with adding this as long as it does not break existing code.
Can you add an argument to the addon which would toggle on the new behaviour while preserving the existing as the default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants