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

merged 1 commit into from Feb 24, 2012

3 participants


When stringifying this data structure,

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

one gets


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


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

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

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