hanami / router

Ruby/Rack HTTP router
http://hanamirb.org
MIT License
362 stars 92 forks source link

Skip attempting to parse unknown types in BodyParser middleware #181

Closed timriley closed 6 years ago

timriley commented 6 years ago

This is a narrowed-down PR based on the work I did in #180, focusing on the bug fix only, and leaving the refactoring work to be addressed in a separate follow-up PR.

This PR resolves #179. Now, when a BodyParser middleware is loaded, and the request’s content type does not match any of the loaded parser, it does not attempt to parse and symbolize the body. This ensures there will be no unexpected content in the resulting request env hash.

To make this concrete, given a BodyParser loaded, with :json as its only configured content type, when an ordinary x-www-form-urlencoded request comes through, it's body will not be parsed, allowing Rack to parse it properly later on. This means we end up with params like this:

{:hanami => "ok"}

And not like this:

{:hanami => "ok", :_ => "hamami=ok"}

More details of the bug this fixes are in #179.

@jodosha Hopefully this is focused enough for you to review and merge? Once this is merged I'll follow up with the refactoring PR.


Fixes https://github.com/hanami/router/issues/179