Permalink
Browse files

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

Backports #8855.
  • Loading branch information...
1 parent 1b35a85 commit c669a9c06c0035972cf4efbbecfd96a2a196d2c8 @dylanahsmith dylanahsmith committed Jan 9, 2013
View
@@ -1,5 +1,7 @@
## Rails 3.1.11 (unreleased)
+* Fixed JSON params parsing regression for non-object JSON content.
+
## Rails 3.1.10 (Jan 8, 2013)
* Strip nils from collections on JSON and XML posts. [CVE-2013-0155]
@@ -44,10 +44,10 @@ def parse_formatted_parameters(env)
when :yaml
YAML.load(request.raw_post)
when :json
- data = request.deep_munge ActiveSupport::JSON.decode(request.body)
+ data = ActiveSupport::JSON.decode(request.body)
request.body.rewind if request.body.respond_to?(:rewind)
data = {:_json => data} unless data.is_a?(Hash)
- data.with_indifferent_access
+ request.deep_munge(data).with_indifferent_access
else
false
end
@@ -112,6 +112,13 @@ def teardown
)
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

0 comments on commit c669a9c

Please sign in to comment.