summary refs log tree commit
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-05-14 08:57:02 +0800
committerJoshua Peek <josh@joshpeek.com>2009-05-16 00:29:54 +0800
commit01c17705195577c2df955a606ccd9f4f4026756d (patch)
tree8b2b397a1916ea190618d06f9ffeb7e99520aa01
parent761c6246e18b92752353c0f412976ded4a417dc5 (diff)
downloadrack-01c17705195577c2df955a606ccd9f4f4026756d.tar.gz
Rack::Request#POST raises if rack.input is missing instead of returning the uninitialized rack.request.form_hash
Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r--lib/rack/request.rb4
-rw-r--r--test/spec_rack_request.rb5
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index be534a85..4c4cf61a 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -125,7 +125,9 @@ module Rack
     # This method support both application/x-www-form-urlencoded and
     # multipart/form-data.
     def POST
-      if @env["rack.request.form_input"].eql? @env["rack.input"]
+      if @env["rack.input"].nil?
+        raise "Missing rack.input"
+      elsif @env["rack.request.form_input"].eql? @env["rack.input"]
         @env["rack.request.form_hash"]
       elsif form_data? || parseable_data?
         @env["rack.request.form_input"] = @env["rack.input"]
diff --git a/test/spec_rack_request.rb b/test/spec_rack_request.rb
index 7e4be775..81f05eba 100644
--- a/test/spec_rack_request.rb
+++ b/test/spec_rack_request.rb
@@ -47,6 +47,11 @@ context "Rack::Request" do
     req.params.should.equal "foo" => "bar", "quux" => "bla"
   end
 
+  specify "raises if rack.input is missing" do
+    req = Rack::Request.new({})
+    lambda { req.POST }.should.raise(RuntimeError)
+  end
+
   specify "can parse POST data" do
     req = Rack::Request.new \
       Rack::MockRequest.env_for("/?foo=quux", :input => "foo=bar&quux=bla")