diff options
author | Jason Staten <jstaten07@gmail.com> | 2013-07-18 17:19:32 -0600 |
---|---|---|
committer | Jason Staten <jstaten07@gmail.com> | 2013-07-18 17:19:32 -0600 |
commit | b0593078ce792a380779528a6a135c066aa03515 (patch) | |
tree | 16a2b6476ba5be7de44fbd79cadd427f331b6fe7 | |
parent | 6829a8a0f416ea49a18f1e3e532ed1ece24e9ea4 (diff) | |
download | rack-b0593078ce792a380779528a6a135c066aa03515.tar.gz |
Use equal? to compare form_input to rack.input
Using equal? provides consistent results of equality between 1.8, 1.9, and 2.0 when comparing Tempfile objects. In 1.8, == will change the position of the Tempfile. In 1.9+, == compares Tempfiles correctly. In 1.8, eql? compares Tempfiles correctly In 1.9+, t.eql?(t) always returns false
-rw-r--r-- | lib/rack/request.rb | 2 | ||||
-rw-r--r-- | test/spec_request.rb | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb index f3a048ab..31c36537 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -204,7 +204,7 @@ module Rack def POST if @env["rack.input"].nil? raise "Missing rack.input" - elsif @env["rack.request.form_input"].eql? @env["rack.input"] + elsif @env["rack.request.form_input"].equal? @env["rack.input"] @env["rack.request.form_hash"] elsif form_data? || parseable_data? unless @env["rack.request.form_hash"] = parse_multipart(env) diff --git a/test/spec_request.rb b/test/spec_request.rb index 039aae6b..a3f42379 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -878,6 +878,21 @@ EOF lambda{ req.POST }.should.not.raise("input re-processed!") end + should "use form_hash when form_input is a Tempfile" do + input = "{foo: 'bar'}" + + rack_input = Tempfile.new("rackspec") + rack_input.write(input) + rack_input.rewind + + req = Rack::Request.new Rack::MockRequest.env_for("/", + "rack.request.form_hash" => {'foo' => 'bar'}, + "rack.request.form_input" => rack_input, + :input => rack_input) + + req.POST.should.equal(req.env['rack.request.form_hash']) + end + should "conform to the Rack spec" do app = lambda { |env| content = Rack::Request.new(env).POST["file"].inspect |