Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

querystring.stringify creates different results depending on object property order #14568

Closed
SimplGy opened this issue Apr 8, 2015 · 0 comments

Comments

@SimplGy
Copy link

SimplGy commented Apr 8, 2015

> qs = require('querystring')
> qs.stringify({foo:'foo',bar:'bar'})
'foo=foo&bar=bar'
> qs.stringify({bar:'bar',foo:'foo'})
'bar=bar&foo=foo'

Even though all modern JS interpreters iterate object properties in the order that they are defined, this is not to be counted on from the spec, which says object property order is not guaranteed.

Maybe (probably) non-deterministic query string output is acceptable to most people since the query string spec doesn't care about order. If you are using this for something else though, maybe you care about the param order. I need to for my use case.

Alphabetizing before stringifying is an easy solution.

Seems like a candidate to go into core, but I understand if it's not seen as needed.

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

No branches or pull requests

3 participants