mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix ActionDispatch::ParamsParser::ParseError message for XML and JSON parsers.
This commit is contained in:
parent
d14e2e5a21
commit
b6ba012032
3 changed files with 6 additions and 6 deletions
|
@ -40,14 +40,12 @@ module ActionDispatch
|
||||||
when Proc
|
when Proc
|
||||||
strategy.call(request.raw_post)
|
strategy.call(request.raw_post)
|
||||||
when :xml_simple, :xml_node
|
when :xml_simple, :xml_node
|
||||||
data = Hash.from_xml(request.body.read) || {}
|
data = Hash.from_xml(request.raw_post) || {}
|
||||||
request.body.rewind if request.body.respond_to?(:rewind)
|
|
||||||
data.with_indifferent_access
|
data.with_indifferent_access
|
||||||
when :yaml
|
when :yaml
|
||||||
YAML.load(request.raw_post)
|
YAML.load(request.raw_post)
|
||||||
when :json
|
when :json
|
||||||
data = ActiveSupport::JSON.decode(request.body)
|
data = ActiveSupport::JSON.decode(request.raw_post)
|
||||||
request.body.rewind if request.body.respond_to?(:rewind)
|
|
||||||
data = {:_json => data} unless data.is_a?(Hash)
|
data = {:_json => data} unless data.is_a?(Hash)
|
||||||
data.with_indifferent_access
|
data.with_indifferent_access
|
||||||
else
|
else
|
||||||
|
|
|
@ -46,7 +46,8 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest
|
||||||
begin
|
begin
|
||||||
$stderr = StringIO.new # suppress the log
|
$stderr = StringIO.new # suppress the log
|
||||||
json = "[\"person]\": {\"name\": \"David\"}}"
|
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
|
ensure
|
||||||
$stderr = STDERR
|
$stderr = STDERR
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,7 +68,8 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest
|
||||||
begin
|
begin
|
||||||
$stderr = StringIO.new # suppress the log
|
$stderr = StringIO.new # suppress the log
|
||||||
xml = "<person><name>David</name></pineapple>"
|
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
|
ensure
|
||||||
$stderr = STDERR
|
$stderr = STDERR
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue