diff --git a/lib/rack/method_override.rb b/lib/rack/method_override.rb index 244214b10..06df21f7b 100644 --- a/lib/rack/method_override.rb +++ b/lib/rack/method_override.rb @@ -37,7 +37,10 @@ def allowed_methods def method_override_param(req) req.POST[METHOD_OVERRIDE_PARAM_KEY] - rescue Utils::InvalidParameterError, Utils::ParameterTypeError, EOFError + rescue Utils::InvalidParameterError, Utils::ParameterTypeError + req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params" + rescue EOFError + req.get_header(RACK_ERRORS).puts "Bad request content body" end end end diff --git a/test/spec_method_override.rb b/test/spec_method_override.rb index 9352e399f..bb72af9f3 100644 --- a/test/spec_method_override.rb +++ b/test/spec_method_override.rb @@ -71,6 +71,22 @@ def app env["REQUEST_METHOD"].must_equal "POST" end + it "writes error to RACK_ERRORS when given invalid multipart form data" do + input = < "multipart/form-data, boundary=AaB03x", + "CONTENT_LENGTH" => input.size.to_s, + Rack::RACK_ERRORS => StringIO.new, + :method => "POST", :input => input) + Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env + + env[Rack::RACK_ERRORS].rewind + env[Rack::RACK_ERRORS].read.must_match /Bad request content body/ + end + it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)") app.call env