Permalink
Browse files

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...
jeremy authored and josh committed May 14, 2009
1 parent 761c624 commit 01c17705195577c2df955a606ccd9f4f4026756d
Showing with 8 additions and 1 deletion.
  1. +3 −1 lib/rack/request.rb
  2. +5 −0 test/spec_rack_request.rb
View
@@ -125,7 +125,9 @@ def GET
# 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"]
@@ -47,6 +47,11 @@
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")

0 comments on commit 01c1770

Please sign in to comment.