Skip to content

Commit ea70e02

Browse files
committed
Remove unreachable code, and add additional testcases.
1 parent a93ee92 commit ea70e02

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

actionpack/lib/action_dispatch/middleware/params_parser.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ def parse_formatted_parameters(env)
5454
rescue Exception => e # YAML, XML or Ruby code block errors
5555
logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
5656

57-
raise
58-
{ "body" => request.raw_post,
59-
"content_type" => request.content_mime_type,
60-
"content_length" => request.content_length,
61-
"exception" => "#{e.message} (#{e.class})",
62-
"backtrace" => e.backtrace }
57+
raise e
6358
end
6459

6560
def content_type_from_legacy_post_data_format_header(env)

actionpack/test/dispatch/request/json_params_parsing_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ def teardown
4545
end
4646
end
4747

48+
test "occurring a parse error if parsing unsuccessful" do
49+
with_test_routing do
50+
begin
51+
$stderr = StringIO.new # suppress the log
52+
json = "[\"person]\": {\"name\": \"David\"}}"
53+
assert_raise(MultiJson::DecodeError) { post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => false} }
54+
ensure
55+
$stderr = STDERR
56+
end
57+
end
58+
end
59+
4860
private
4961
def assert_parses(expected, actual, headers = {})
5062
with_test_routing do

actionpack/test/dispatch/request/xml_params_parsing_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def call(env)
6767
end
6868
end
6969

70+
test "occurring a parse error if parsing unsuccessful" do
71+
with_test_routing do
72+
begin
73+
$stderr = StringIO.new # suppress the log
74+
xml = "<person><name>David</name></pineapple>"
75+
assert_raise(REXML::ParseException) { post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => false) }
76+
ensure
77+
$stderr = STDERR
78+
end
79+
end
80+
end
81+
7082
test "parses multiple files" do
7183
xml = <<-end_body
7284
<person>

0 commit comments

Comments
 (0)