Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8855 from dylanahsmith/parse-non-object-json-params

Fix json params parsing regression for non-object JSON content.
  • Loading branch information...
commit 92fada9b8c10b75d88190938ea2fd5a92277697b 2 parents 8a7fad8 + bae9268
Jeremy Kemper jeremy authored
4 actionpack/CHANGELOG.md
View
@@ -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.
4 actionpack/lib/action_dispatch/middleware/params_parser.rb
View
@@ -50,9 +50,9 @@ def parse_formatted_parameters(env)
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
7 actionpack/test/dispatch/request/json_params_parsing_test.rb
View
@@ -122,6 +122,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
Please sign in to comment.
Something went wrong with that request. Please try again.