Skip to content
This repository
Browse code

Fix JSON params parsing regression for non-object JSON content.

Backports #8855.
  • Loading branch information...
commit c669a9c06c0035972cf4efbbecfd96a2a196d2c8 1 parent 1b35a85
Dylan Thacker-Smith authored January 09, 2013
2  actionpack/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,7 @@
1 1
 ## Rails 3.1.11 (unreleased)
2 2
 
  3
+* Fixed JSON params parsing regression for non-object JSON content.
  4
+
3 5
 ## Rails 3.1.10 (Jan 8, 2013)
4 6
 
5 7
 * Strip nils from collections on JSON and XML posts. [CVE-2013-0155]
4  actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -44,10 +44,10 @@ def parse_formatted_parameters(env)
44 44
         when :yaml
45 45
           YAML.load(request.raw_post)
46 46
         when :json
47  
-          data = request.deep_munge ActiveSupport::JSON.decode(request.body)
  47
+          data = ActiveSupport::JSON.decode(request.body)
48 48
           request.body.rewind if request.body.respond_to?(:rewind)
49 49
           data = {:_json => data} unless data.is_a?(Hash)
50  
-          data.with_indifferent_access
  50
+          request.deep_munge(data).with_indifferent_access
51 51
         else
52 52
           false
53 53
         end
7  actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -112,6 +112,13 @@ def teardown
112 112
     )
113 113
   end
114 114
 
  115
+  test "parses json with non-object JSON content" do
  116
+    assert_parses(
  117
+      {"user" => {"_json" => "string content" }, "_json" => "string content" },
  118
+      "\"string content\"", { 'CONTENT_TYPE' => 'application/json' }
  119
+    )
  120
+  end
  121
+
115 122
   private
116 123
     def assert_parses(expected, actual, headers = {})
117 124
       with_test_routing(UsersController) do

0 notes on commit c669a9c

Please sign in to comment.
Something went wrong with that request. Please try again.