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

qs.parse is parsing the string with + properly #305

Closed
ernitinjain opened this issue Feb 2, 2021 · 4 comments
Closed

qs.parse is parsing the string with + properly #305

ernitinjain opened this issue Feb 2, 2021 · 4 comments

Comments

@ernitinjain
Copy link

?externaluserid=454545454&email=abc+123@gmail.com&order=165615&token=dtc5uwvmkC

is converting the email's + to a space.

{email: "abc 123@gmail.com", externaluserid: "454545454", token: "dtc5uwvmkC", order: "165615"}

It should keep + in email instead of converting this to a space.

@sindresorhus
Copy link
Owner

+ is a space in a query string. You need to properly encode the value.

https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20

@aneena-thomas
Copy link

@sindresorhus Not working

@sindresorhus
Copy link
Owner

This is the behavior of the browser API too:

> let x = new URLSearchParams('?externaluserid=454545454&email=abc+123@gmail.com&order=165615&token=dtc5uwvmkC')
x.get('email')
< "abc 123@gmail.com"

And this is how it should have looked like if it had been properly encoded:

> let x = new URLSearchParams({email: 'abc+123@gmail.com'})
x.toString()
< "email=abc%2B123%40gmail.com"

@msudgh
Copy link

msudgh commented Jun 25, 2021

In such cases, I think using Base64 is much safer than passing it as a raw string.

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

No branches or pull requests

4 participants