Skip to content

Commit

Permalink
Merge pull request rails#3735 from kennyj/fix_3728
Browse files Browse the repository at this point in the history
Fix rails#3728 Remove unreachable code, and add additional testcases.
  • Loading branch information
josevalim committed Nov 23, 2011
2 parents a93ee92 + ea70e02 commit f62f545
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 1 addition & 6 deletions actionpack/lib/action_dispatch/middleware/params_parser.rb
Expand Up @@ -54,12 +54,7 @@ def parse_formatted_parameters(env)
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)
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/request/json_params_parsing_test.rb
Expand Up @@ -45,6 +45,18 @@ def teardown
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
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/request/xml_params_parsing_test.rb
Expand Up @@ -67,6 +67,18 @@ def call(env)
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>
Expand Down

0 comments on commit f62f545

Please sign in to comment.