diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-14 08:57:02 +0800 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-05-16 00:29:54 +0800 |
commit | 01c17705195577c2df955a606ccd9f4f4026756d (patch) | |
tree | 8b2b397a1916ea190618d06f9ffeb7e99520aa01 | |
parent | 761c6246e18b92752353c0f412976ded4a417dc5 (diff) | |
download | rack-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.rb | 4 | ||||
-rw-r--r-- | test/spec_rack_request.rb | 5 |
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") |