Permalink
Browse files

Merge pull request #11353 from jetthoughts/revert_to_raw_post

Use Request#raw_post instead Request#body in ParamsParser#parse_formatted_parameters
  • Loading branch information...
2 parents 74da4d1 + f6746c0 commit 590c9d418ae8e81ae6fca9b3c0d40e3a82a05ea6 @rafaelfranca rafaelfranca committed Jul 9, 2013
View
@@ -1,3 +1,10 @@
+* Fix `ActionDispatch::ParamsParser#parse_formatted_parameters` to rewind body input stream on
+ parsing json params.
+
+ Fixes #11345
+
+ *Yuri Bol*, *Paul Nikitochkin*
+
* Ignore spaces around delimiter in Set-Cookie header.
*Yamagishi Kazutoshi*
@@ -41,7 +41,7 @@ def parse_formatted_parameters(env)
when Proc
strategy.call(request.raw_post)
when :json
- data = ActiveSupport::JSON.decode(request.body)
+ data = ActiveSupport::JSON.decode(request.raw_post)
data = {:_json => data} unless data.is_a?(Hash)
Request::Utils.deep_munge(data).with_indifferent_access
else
@@ -70,6 +70,13 @@ def teardown
end
end
+ test 'raw_post is not empty for JSON request' do
+ with_test_routing do
+ post '/parse', '{"posts": [{"title": "Post Title"}]}', 'CONTENT_TYPE' => 'application/json'
+ assert_equal '{"posts": [{"title": "Post Title"}]}', request.raw_post
+ end
+ end
+
private
def assert_parses(expected, actual, headers = {})
with_test_routing do

0 comments on commit 590c9d4

Please sign in to comment.