Skip to content

Commit

Permalink
Use equal? to compare form_input to rack.input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
statianzo committed Jul 18, 2013
1 parent 6829a8a commit b059307
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def GET
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)
Expand Down
15 changes: 15 additions & 0 deletions test/spec_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,21 @@
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
Expand Down

0 comments on commit b059307

Please sign in to comment.