sindresorhus/query-string

qs.parse is parsing the string with + properly

ernitinjain opened this issue · 4 comments

?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.

+ 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

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"

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