summary refs log tree commit
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-12-29 15:54:10 -0500
committerGitHub <noreply@github.com>2016-12-29 15:54:10 -0500
commitbfd4c155a9ba2fb1fcee8daab433fbdef582cce2 (patch)
treed1a0fdfdc363f5cb6dd5b5cc4676d2544db3a56a
parent9e73bd1ae7b5df937302a148ab99bf3be12eb063 (diff)
parentea8479d606a6afda08ecb89057e5593f04fd5f3b (diff)
downloadrack-bfd4c155a9ba2fb1fcee8daab433fbdef582cce2.tar.gz
Merge pull request #1137 from unabridged/fix-eof-failure
Fix MethodOverride EOFError failure
-rw-r--r--lib/rack/method_override.rb3
-rw-r--r--test/spec_method_override.rb21
-rw-r--r--test/spec_webrick.rb1
3 files changed, 21 insertions, 4 deletions
diff --git a/lib/rack/method_override.rb b/lib/rack/method_override.rb
index f5637771..06df21f7 100644
--- a/lib/rack/method_override.rb
+++ b/lib/rack/method_override.rb
@@ -38,6 +38,9 @@ module Rack
     def method_override_param(req)
       req.POST[METHOD_OVERRIDE_PARAM_KEY]
     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 14ace0b1..bb72af9f 100644
--- a/test/spec_method_override.rb
+++ b/test/spec_method_override.rb
@@ -66,14 +66,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"].must_equal "POST"
   end
 
+  it "writes 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::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
diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb
index 469ae62a..eff64116 100644
--- a/test/spec_webrick.rb
+++ b/test/spec_webrick.rb
@@ -1,5 +1,6 @@
 require 'minitest/autorun'
 require 'rack/mock'
+require 'concurrent/utility/native_integer'
 require 'concurrent/atomic/count_down_latch'
 require File.expand_path('../testrequest', __FILE__)