diff options
author | Dylan Smith <Dylan.Smith@shopify.com> | 2013-01-09 15:26:12 -0500 |
---|---|---|
committer | Dylan Smith <Dylan.Smith@shopify.com> | 2013-01-11 00:28:32 -0500 |
commit | bae92681be97191edda90990e08b5275d187107f (patch) | |
tree | 71445260ff346809533fa27a993995f3f2b6ffd1 /actionpack | |
parent | 8a7fad8970aadea3a79657ef09d3247786e27c2e (diff) | |
download | rails-bae92681be97191edda90990e08b5275d187107f.tar.gz rails-bae92681be97191edda90990e08b5275d187107f.tar.bz2 rails-bae92681be97191edda90990e08b5275d187107f.zip |
Fix json params parsing regression for non-object JSON content.
Fixes #8845.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/json_params_parsing_test.rb | 7 |
3 files changed, 13 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 7dea0e7fa5..2cb7af05e5 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,9 @@ ## 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 You can add the gem to your Gemfile to keep using performance tests. diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index a3291bb7ad..0898ad82dd 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -50,9 +50,9 @@ module ActionDispatch data = request.deep_munge(Hash.from_xml(request.body.read) || {}) data.with_indifferent_access 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.with_indifferent_access + request.deep_munge(data).with_indifferent_access else false end diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index 2c4a6c2147..7d3fc84089 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -122,6 +122,13 @@ class RootLessJSONParamsParsingTest < ActionDispatch::IntegrationTest ) 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 def assert_parses(expected, actual, headers = {}) with_test_routing(UsersController) do |