Skip to content

Commit

Permalink
Merge pull request #1237 from eileencodes/backport-1137
Browse files Browse the repository at this point in the history
Backport pull request #1137 from unabridged/fix-eof-failure
  • Loading branch information
eileencodes authored Feb 27, 2018
2 parents 90afdf3 + 4d6965a commit dc017e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/rack/methodoverride.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def allowed_methods
def method_override_param(req)
req.POST[METHOD_OVERRIDE_PARAM_KEY]
rescue Utils::InvalidParameterError, Utils::ParameterTypeError
req.env["rack.errors"].puts "Invalid or incomplete POST params"
rescue EOFError
req.env["rack.errors"].puts "Bad request content body"
end
end
end
21 changes: 17 additions & 4 deletions test/spec_methodoverride.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,27 @@ def app
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
"CONTENT_LENGTH" => input.size.to_s,
:method => "POST", :input => input)
begin
app.call env
rescue EOFError
end
app.call env

env["REQUEST_METHOD"].should.equal "POST"
end

should "write error to RACK_ERRORS when given invalid multipart form data" do
input = <<EOF
--AaB03x\r
content-disposition: form-data; name="huge"; filename="huge"\r
EOF
env = Rack::MockRequest.env_for("/",
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
"CONTENT_LENGTH" => input.size.to_s,
"rack.errors" => StringIO.new,
:method => "POST", :input => input)
Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env

env["rack.errors"].rewind
env["rack.errors"].read.should =~ /Bad request content body/
end

should "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
Expand Down

0 comments on commit dc017e7

Please sign in to comment.