Skip to content

Commit

Permalink
Merge pull request #8889 from dylanahsmith/3-1-parse-non-object-json-…
Browse files Browse the repository at this point in the history
…params

3-1-stable: Fix JSON params parsing regression for non-object JSON content.
  • Loading branch information
jeremy committed Jan 11, 2013
2 parents 1b35a85 + c669a9c commit 18b8f90
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG.md
@@ -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]
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/middleware/params_parser.rb
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/dispatch/request/json_params_parsing_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 18b8f90

Please sign in to comment.