Skip to content
This repository
Browse code

Remove unreachable code, and add additional testcases.

  • Loading branch information...
commit ea70e027b63a1b8bfe4087a4de978ad4eef5575b 1 parent a93ee92
Toshinori Kajihara kennyj authored
7 actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -54,12 +54,7 @@ def parse_formatted_parameters(env)
54 54 rescue Exception => e # YAML, XML or Ruby code block errors
55 55 logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{request.raw_post}"
56 56
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
63 58 end
64 59
65 60 def content_type_from_legacy_post_data_format_header(env)
12 actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -45,6 +45,18 @@ def teardown
45 45 end
46 46 end
47 47
  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 +
48 60 private
49 61 def assert_parses(expected, actual, headers = {})
50 62 with_test_routing do
12 actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -67,6 +67,18 @@ def call(env)
67 67 end
68 68 end
69 69
  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 +
70 82 test "parses multiple files" do
71 83 xml = <<-end_body
72 84 <person>

0 comments on commit ea70e02

Please sign in to comment.
Something went wrong with that request. Please try again.