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

round tripping an object whose first keys are numeric does not work #26

Open
binki opened this issue Aug 21, 2020 · 0 comments
Open

round tripping an object whose first keys are numeric does not work #26

binki opened this issue Aug 21, 2020 · 0 comments

Comments

@binki
Copy link

binki commented Aug 21, 2020

> jQuery.param({a:{'0':1,x:4}})
'a%5B0%5D=1&a%5Bx%5D=4'
> jqueryDeparam(jQuery.param(jqueryDeparam(jQuery.param({a:{'0':1,x:4}}))))
{ a: [ '1' ] }
> jqueryDeparam(jQuery.param(jqueryDeparam(jQuery.param({a:{'0':1,x:4}})))).a.x
undefined
> jqueryDeparam(jQuery.param({a:{'0':1,x:4}})).a.x
'4'
> typeof jqueryDeparam(jQuery.param({a:{'0':1,x:4}})).a
'object'
> jQuery.isArray(jqueryDeparam(jQuery.param({a:{'0':1,x:4}})).a)
true

An object with numeric keys is encoded in the same way as an array by jQuery.param(). jQuery.param() will, like JSON.stringify(), ignore any string keys on an array object when serializing. However, this package, jquery-deparam assumes that an object is an array if the first key name it encounters is numeric.

jquery-param treats things as arrays sometims when it shouldn’t. As a result, the transform becomes lossy.

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

1 participant