Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added a numeric index in array stringify to preserve reversability #32

Merged
merged 1 commit into from Feb 24, 2012

Conversation

Projects
None yet
3 participants

yadutaf commented Feb 24, 2012

When stringifying this data structure,

{
    name: "answer #2",
    choices: [
        {propositionid:'4f47bfe1bc9dd1432900000a', dispo: 'yes'},
            {propositionid:'4f47bfe1bc9dd14329000009', dispo: 'no'}
    ]
}

one gets

name=answer%20%232&choices[][propositionid]=4f47bfe1bc9dd1432900000a&choices[][dispo]=yes&choices[][propositionid]=4f47bfe1bc9dd14329000009&choices[][dispo]=no

As you can notice, there is an ambiguity that prevents the parser from building the data-structure back. When generated this way

name=answer%20%232&choices[0][propositionid]=4f47bfe1bc9dd1432900000a&choices[0][dispo]=yes&choices[1][propositionid]=4f47bfe1bc9dd14329000009&choices[1][dispo]=no

Then, everything is alright again. Here is a tentative to fix it.

@tj tj added a commit that referenced this pull request Feb 24, 2012

@tj tj Merge pull request #32 from jtlebi/master
Added a numeric index in array stringify to preserve reversability
5a989a2

@tj tj merged commit 5a989a2 into tj:master Feb 24, 2012

jeffjo commented Jan 24, 2014

When Rails ActionController parses URL parameters, it expects arrays to be encoded without indices:

qs.stringify({a: [1, 2, 3]}) => a[]=1&a[]=2&a[]=3

Is there any way we can bring this behavior back as an option to stringify()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment