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

unexpected encode behaviour for set query #220

Open
herbertpimentel opened this issue Dec 23, 2021 · 1 comment
Open

unexpected encode behaviour for set query #220

herbertpimentel opened this issue Dec 23, 2021 · 1 comment

Comments

@herbertpimentel
Copy link

herbertpimentel commented Dec 23, 2021

It results unexpected encoding, depending of the type of input used on set query

var parsed = urlParse('http://go.com/');

parsed.set('query', 'promo=20%25');
console.log(parsed.href);   //outputs: "http://go.com/?promo=20%25"

parsed.set('query', {promo:'20%25'});
console.log(parsed.href);   //outputs: "http://go.com/?promo=20%2525"

https://codepen.io/herbertpimentel/pen/vYeeVdz?editors=0011

Expected result: in both cases have the same output.

@lpinca
Copy link
Member

lpinca commented Dec 23, 2021

This is expected, in the first case the query string is first parsed so you get

{ promo: '20%' }

which is then stringified to 'promo=20%25'.

In the second case you are providing an already parsed query string which is only stringified.

> querystring.stringify({ promo: '20%25' })
'promo=20%2525'

to get the expected result you should use { promo: '20%' }

> querystring.stringify({ promo: '20%' })
'promo=20%25'

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

2 participants