Merge pull request #3735 from kennyj/fix_3728

Fix #3728 Remove unreachable code, and add additional testcases.
This commit is contained in:
José Valim
2011-11-23 09:55:31 -08:00
3 changed files with 25 additions and 6 deletions

View File

@@ -54,12 +54,7 @@ module ActionDispatch
rescue Exception => e # YAML, XML or Ruby code block errors
logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
raise
{ "body" => request.raw_post,
"content_type" => request.content_mime_type,
"content_length" => request.content_length,
"exception" => "#{e.message} (#{e.class})",
"backtrace" => e.backtrace }
raise e
end
def content_type_from_legacy_post_data_format_header(env)

View File

@@ -45,6 +45,18 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest
end
end
test "occurring a parse error if parsing unsuccessful" do
with_test_routing do
begin
$stderr = StringIO.new # suppress the log
json = "[\"person]\": {\"name\": \"David\"}}"
assert_raise(MultiJson::DecodeError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
ensure
$stderr = STDERR
end
end
end
private
def assert_parses(expected, actual, headers = {})
with_test_routing do

View File

@@ -67,6 +67,18 @@ class XmlParamsParsingTest < ActionDispatch::IntegrationTest
end
end
test "occurring a parse error if parsing unsuccessful" do
with_test_routing do
begin
$stderr = StringIO.new # suppress the log
xml = "<person><name>David</name></pineapple>"
assert_raise(REXML::ParseException) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) }
ensure
$stderr = STDERR
end
end
end
test "parses multiple files" do
xml = <<-end_body
<person>