Skip to content

Commit

Permalink
Merge branch 'master' into 0.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Nov 14, 2016
2 parents 01f40d3 + f54191a commit cf12b6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Rack compatible HTTP router for Ruby
- [Kyle Chong] Referenced params from body parses in Rack env via `router.parsed_body`

### Fixed
- [Luca Guidi] Ensure params from routes take precedence over params from body parsing
- [Luca Guidi & Lucas Hosseini] Ensure params from routes take precedence over params from body parsing
- [Luca Guidi] Ensure inspector to respect path prefix of mouted apps

### Changed
Expand Down
22 changes: 11 additions & 11 deletions lib/hanami/routing/parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,25 @@ def _redefine_call
env[RACK_INPUT].rewind # somebody might try to read this stream

env[ROUTER_PARAMS] ||= {} # prepare params
parsed_body = _parse(env, body)
env[ROUTER_PARSED_BODY] = parsed_body
env[ROUTER_PARAMS] = parsed_body.merge(env[ROUTER_PARAMS])
env[ROUTER_PARSED_BODY] = _parse(env, body)
env[ROUTER_PARAMS] = _symbolize(env[ROUTER_PARSED_BODY]).merge(env[ROUTER_PARAMS])

env
end
end

def _symbolize(body)
if body.is_a?(Hash)
Utils::Hash.new(body).deep_dup.symbolize!.to_h
else
{ FALLBACK_KEY => body }
end
end

def _parse(env, body)
result = @parsers[
@parsers[
media_type(env)
].parse(body)

case result
when Hash
Utils::Hash.new(result).symbolize!.to_h
else
{FALLBACK_KEY => result}
end
end

def media_type(env)
Expand Down
6 changes: 3 additions & 3 deletions test/routing/parsers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

it "stores parsed body" do
result = @parsers.call(env)
result['router.parsed_body'].must_equal({attribute: "ok"})
result['router.parsed_body'].must_equal({'attribute' => "ok"})
end

describe "with non hash body" do
Expand All @@ -64,7 +64,7 @@

it "stores parsed body" do
result = @parsers.call(env)
result['router.parsed_body'].must_equal({"_" => ["foo"]})
result['router.parsed_body'].must_equal(["foo"])
end
end

Expand All @@ -87,7 +87,7 @@

it "stores parsed body" do
result = @parsers.call(env)
result['router.parsed_body'].must_equal({attribute: "ok"})
result['router.parsed_body'].must_equal({'attribute' => "ok"})
end

describe 'with malformed json' do
Expand Down

0 comments on commit cf12b6e

Please sign in to comment.