Skip to content
This repository
Browse code

Rack::Request#POST raises if rack.input is missing instead of returni…

…ng the uninitialized rack.request.form_hash

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 01c17705195577c2df955a606ccd9f4f4026756d 1 parent 761c624
Jeremy Kemper authored May 14, 2009 josh committed May 16, 2009
4  lib/rack/request.rb
@@ -125,7 +125,9 @@ def GET
125 125
     # This method support both application/x-www-form-urlencoded and
126 126
     # multipart/form-data.
127 127
     def POST
128  
-      if @env["rack.request.form_input"].eql? @env["rack.input"]
  128
+      if @env["rack.input"].nil?
  129
+        raise "Missing rack.input"
  130
+      elsif @env["rack.request.form_input"].eql? @env["rack.input"]
129 131
         @env["rack.request.form_hash"]
130 132
       elsif form_data? || parseable_data?
131 133
         @env["rack.request.form_input"] = @env["rack.input"]
5  test/spec_rack_request.rb
@@ -47,6 +47,11 @@
47 47
     req.params.should.equal "foo" => "bar", "quux" => "bla"
48 48
   end
49 49
 
  50
+  specify "raises if rack.input is missing" do
  51
+    req = Rack::Request.new({})
  52
+    lambda { req.POST }.should.raise(RuntimeError)
  53
+  end
  54
+
50 55
   specify "can parse POST data" do
51 56
     req = Rack::Request.new \
52 57
       Rack::MockRequest.env_for("/?foo=quux", :input => "foo=bar&quux=bla")

0 notes on commit 01c1770

Please sign in to comment.
Something went wrong with that request. Please try again.