Skip to content

Commit

Permalink
Fix json params parsing regression for non-object JSON content.
Browse files Browse the repository at this point in the history
Fixes #8845.
  • Loading branch information
dylanahsmith committed Jan 11, 2013
1 parent 8a7fad8 commit bae9268
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ## ## Rails 4.0.0 (unreleased) ##


* Fixed json params parsing regression for non-object JSON content.

*Dylan Smith*

* Extract `ActionDispatch::PerformanceTest` into https://github.com/rails/rails-perftest * Extract `ActionDispatch::PerformanceTest` into https://github.com/rails/rails-perftest
You can add the gem to your Gemfile to keep using performance tests. You can add the gem to your Gemfile to keep using performance tests.


Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/middleware/params_parser.rb
Expand Up @@ -50,9 +50,9 @@ def parse_formatted_parameters(env)
data = request.deep_munge(Hash.from_xml(request.body.read) || {}) data = request.deep_munge(Hash.from_xml(request.body.read) || {})
data.with_indifferent_access data.with_indifferent_access
when :json when :json
data = request.deep_munge ActiveSupport::JSON.decode(request.body) data = ActiveSupport::JSON.decode(request.body)
data = {:_json => data} unless data.is_a?(Hash) data = {:_json => data} unless data.is_a?(Hash)
data.with_indifferent_access request.deep_munge(data).with_indifferent_access
else else
false false
end end
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/request/json_params_parsing_test.rb
Expand Up @@ -122,6 +122,13 @@ def teardown
) )
end end


test "parses json with non-object JSON content" do
assert_parses(
{"user" => {"_json" => "string content" }, "_json" => "string content" },
"\"string content\"", { 'CONTENT_TYPE' => 'application/json' }
)
end

private private
def assert_parses(expected, actual, headers = {}) def assert_parses(expected, actual, headers = {})
with_test_routing(UsersController) do with_test_routing(UsersController) do
Expand Down

0 comments on commit bae9268

Please sign in to comment.