summary refs log tree commit
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2018-02-26 14:08:56 -0500
committereileencodes <eileencodes@gmail.com>2018-02-26 14:08:56 -0500
commit4d6965abb840d4543bcaf00e96482afe94442045 (patch)
tree85557c5f612eaef182b63cc457f399f6741f1fd0
parent90afdf309b4c0665f542579a21fbd1c285d05083 (diff)
downloadrack-4d6965abb840d4543bcaf00e96482afe94442045.tar.gz
Backport pull request #1137 from unabridged/fix-eof-failure
Original commit message:
Fix MethodOverride EOFError failure

Converted changes from Rack 2.0 to work in Rack 1.6 which included
changing `RACK_ERRORS` to `rack.errors` and fixes to the tests (`it` to
`should` and `must_match` to `should =~`.
-rw-r--r--lib/rack/methodoverride.rb3
-rw-r--r--test/spec_methodoverride.rb21
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/rack/methodoverride.rb b/lib/rack/methodoverride.rb
index c0963c1a..16bf23cf 100644
--- a/lib/rack/methodoverride.rb
+++ b/lib/rack/methodoverride.rb
@@ -38,6 +38,9 @@ module Rack
     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
diff --git a/test/spec_methodoverride.rb b/test/spec_methodoverride.rb
index c62fcdc5..6914bdee 100644
--- a/test/spec_methodoverride.rb
+++ b/test/spec_methodoverride.rb
@@ -65,14 +65,27 @@ EOF
                       "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