Skip to content
This repository

Object.toQueryString() and Element.toQueryString() #2356

Closed
piotr-cz opened this Issue April 30, 2012 · 4 comments

4 participants

Piotr Olmo Maldonado Dimitar Christoff Arian Stolwijk
Piotr

Object.toQueryString() doesn't encode keys, while Element.toQueryString() does.

see
http://jsfiddle.net/piotr_cz/y28zb/

So I guess in Object.toQueryString

default: result = key + '=' + encodeURIComponent(value);
should just be
default: result = encodeURIComponent(key) + '=' + encodeURIComponent(value);

Dimitar Christoff

what is your use case? prototypejs don't encode keys either - https://github.com/sstephenson/prototype/blob/master/src/prototype/lang/hash.js#L289

Piotr

@DimitarChristoff:
The thing is that one function does encode keys, while another doesn't. Check jsFiddle output:

element => queryString

$form.toQueryString()
> params%5Blanguage%5D=en-GB&params%5Btimezone%5D=1

element => object => queryString

Object.toQueryString( $form.toQueryString().parseQueryString() )
> params[language]=en-GB&params[timezone]=1
Arian Stolwijk
Owner

what do others do?

for example nodejs simply does this: querystring.stringify({a: 1, b: {c: 2}}); => 'a=1&b=', so it's probably a bit server specific.. are there any other good examples?

Also isn't e4e637a / https://mootools.lighthouseapp.com/projects/2706/tickets/762 related?

Olmo Maldonado
Owner

Assuming fixed. Reopen if still an issue.

Olmo Maldonado ibolmo closed this March 03, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.