brynary/rack-test — pull request #69 by h-lame (2012-12-14 15:33:04+00:00)
Title: Provide full support for arrays of hashes in multipart forms

The @econsultancy fix (#41) only partially fixed the problem. If the hashes had more than one key they would be rendered so that all the values for a given subkey would be together.

e.g. given:

blah: [{id: 1, name: 'dave'}, {id: 2, name: 'steve'}]

then the multipart rendering would be

------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][id]"

1
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][id]"

2
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][name]"

dave
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][name]"

steve

which is then parsed out as:

blah: [{id: 1}, {name: 'dave', id: 2}, {name: 'steve'}]

We've fixed it so that the values for each hash are rendered next to each other. So the multipart rendering is:

------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][id]"

1
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][name]"

dave
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][id]"

2
------------XnJLe9ZIbbGUYtzPQJ16u1
Content-Disposition: form-data; name="blah[][name]"

steve

and this is parsed out properly to:

blah: [{id: 1, name: 'dave'}, {id: 2, name: 'steve'}]