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

Don't mangle user-provided searchParams string #325

Merged
merged 1 commit into from
Feb 20, 2021

Conversation

yocontra
Copy link
Contributor

When providing a raw searchParams string, currently ky will pass it through new URLSearchParams() which has the result of mangling it in places where it is perfectly valid. A simple example is a querystring like a&b= (which is the output of qs.stringify({ a: null, b: '' }, { strictNullHandling: true })) is changed to a=&b= which semantically has a different meaning (a and b are both empty string).

This change is pretty simple, if a user provides a string don't mess with it - use it directly. This is a breaking change and should be released as a major if landed. I added one new test for a specific case with null values and also had to update other tests.

Copy link
Collaborator

@sholladay sholladay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good and I agree the behavior is arguably better. Though, by default all of the major parsers treat both ?foo and ?foo= as meaning that foo is an empty string and I'd strongly suggest not changing those defaults, otherwise it'll probably bite you at some point.

@sindresorhus sindresorhus changed the title fix: dont mangle user provided searchParams string Don't mangle user-provided searchParams string Feb 20, 2021
@sindresorhus sindresorhus merged commit 5815518 into sindresorhus:main Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants