Skip to content

Commit

Permalink
Remove unreachable code, and add additional testcases.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Nov 23, 2011
1 parent a93ee92 commit ea70e02
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 rescue Exception => e # YAML, XML or Ruby code block errors
logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}" logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"


raise raise e
{ "body" => request.raw_post,
"content_type" => request.content_mime_type,
"content_length" => request.content_length,
"exception" => "#{e.message} (#{e.class})",
"backtrace" => e.backtrace }
end end


def content_type_from_legacy_post_data_format_header(env) 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
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 private
def assert_parses(expected, actual, headers = {}) def assert_parses(expected, actual, headers = {})
with_test_routing do 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
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 test "parses multiple files" do
xml = <<-end_body xml = <<-end_body
<person> <person>
Expand Down

0 comments on commit ea70e02

Please sign in to comment.