Skip to content

Commit dc017e7

Browse files
authored
Merge pull request #1237 from eileencodes/backport-1137
Backport pull request #1137 from unabridged/fix-eof-failure
2 parents 90afdf3 + 4d6965a commit dc017e7

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/rack/methodoverride.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def allowed_methods
3838
def method_override_param(req)
3939
req.POST[METHOD_OVERRIDE_PARAM_KEY]
4040
rescue Utils::InvalidParameterError, Utils::ParameterTypeError
41+
req.env["rack.errors"].puts "Invalid or incomplete POST params"
42+
rescue EOFError
43+
req.env["rack.errors"].puts "Bad request content body"
4144
end
4245
end
4346
end

test/spec_methodoverride.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,27 @@ def app
6565
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
6666
"CONTENT_LENGTH" => input.size.to_s,
6767
:method => "POST", :input => input)
68-
begin
69-
app.call env
70-
rescue EOFError
71-
end
68+
app.call env
7269

7370
env["REQUEST_METHOD"].should.equal "POST"
7471
end
7572

73+
should "write error to RACK_ERRORS when given invalid multipart form data" do
74+
input = <<EOF
75+
--AaB03x\r
76+
content-disposition: form-data; name="huge"; filename="huge"\r
77+
EOF
78+
env = Rack::MockRequest.env_for("/",
79+
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
80+
"CONTENT_LENGTH" => input.size.to_s,
81+
"rack.errors" => StringIO.new,
82+
:method => "POST", :input => input)
83+
Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env
84+
85+
env["rack.errors"].rewind
86+
env["rack.errors"].read.should =~ /Bad request content body/
87+
end
88+
7689
should "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
7790
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)")
7891
app.call env

0 commit comments

Comments
 (0)