Params middleware errors when a JSON array is posted #218

merged 1 commit into from Nov 30, 2012


None yet
2 participants

radsaq commented Nov 28, 2012

The middleware should not assume that the JSON is always going to evaluate to a hash.


igrigorik commented Nov 28, 2012

Huh.. why? Not sure I follow. What's wrong with an array as an input?


radsaq commented Nov 28, 2012

The code later calls Hash#merge! using the result from the case statement. Naturally, this errors if an array was passed in as the post body.

(For more context, I'm also still using 0.9.4 where this code is used inside of builder.rb, which causes the app to silently and mysteriously fail if you pass a JSON array and an content type of application/json, even without explicitly using the middleware: ... But regardless, there's no reason for this code to fail in this case.)


igrigorik commented Nov 29, 2012

Seems like modifying the input payload is the wrong way to go about it.. Perhaps if its an array, we should simply skip the merge? How does Rails handle this case?


radsaq commented Nov 29, 2012

My patch makes the handling be essentially the same as what rails does:


igrigorik commented Nov 30, 2012

Hmm, that's just confusing.. The magic of Rails conventions. :)


igrigorik added a commit that referenced this pull request Nov 30, 2012

Merge pull request #218 from radsaq/fix_json_params
Params middleware errors when a JSON array is posted

@igrigorik igrigorik merged commit 34ac587 into postrank-labs:master Nov 30, 2012

1 check passed

default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment