Skip to content

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

Open
@binki

Description

@binki
> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions