Skip to content
Browse files

Fix ActionDispatch::ParamsParser::ParseError message for XML and JSON…

… parsers.
  • Loading branch information...
1 parent d14e2e5 commit b6ba012032c0c53e4539228b06f3da6d6a5a69bc @szimek szimek committed Aug 24, 2012
View
6 actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -40,14 +40,12 @@ def parse_formatted_parameters(env)
when Proc
strategy.call(request.raw_post)
when :xml_simple, :xml_node
- data = Hash.from_xml(request.body.read) || {}
- request.body.rewind if request.body.respond_to?(:rewind)
+ data = Hash.from_xml(request.raw_post) || {}
data.with_indifferent_access
when :yaml
YAML.load(request.raw_post)
when :json
- data = ActiveSupport::JSON.decode(request.body)
- request.body.rewind if request.body.respond_to?(:rewind)
+ data = ActiveSupport::JSON.decode(request.raw_post)
data = {:_json => data} unless data.is_a?(Hash)
data.with_indifferent_access
else
View
3 actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -46,7 +46,8 @@ def teardown
begin
$stderr = StringIO.new # suppress the log
json = "[\"person]\": {\"name\": \"David\"}}"
- assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
+ exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
+ assert_match json, exception.message
ensure
$stderr = STDERR
end
View
3 actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -68,7 +68,8 @@ def call(env)
begin
$stderr = StringIO.new # suppress the log
xml = "<person><name>David</name></pineapple>"
- assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) }
+ exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) }
+ assert_match xml, exception.message
ensure
$stderr = STDERR
end

0 comments on commit b6ba012

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