rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* .eql? returns false on identity comparison of Tempfiles
@ 2012-06-05 17:05 David LaMacchia
  0 siblings, 0 replies; only message in thread
From: David LaMacchia @ 2012-06-05 17:05 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 1792 bytes --]

I ran into an unusual problem (rails 3.1.3, rack 1.3.6) while using 
rack-multipart_related 
(https://github.com/lucasfais/rack-multipart_related) as middleware to 
handle parsing of a multipart containing an image. While parsing the POST 
request, there's the following code in rack/request.rb:

    def POST
      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?

I noticed that if the size of the image was small, a StringIO is created 
containing the request data and as expected,

@env["rack.request.form_input"].eql? @env["rack.input"]

returns true.  Both operands point to the same StringIO, the object_id's 
are the same.

If the image being uploaded was larger, a Tempfile seems to be created for 
the input and I get a weird result in this same piece of code:

(rdb:1) p @env["rack.request.form_input"]
#<File:/var/folders/_c/0c66qtcm8xjcns006s6bhgzr0000gn/T/thin-body20120604-68121-12dpbf1>
(rdb:1) p @env["rack.request.form_input"].class
Tempfile
(rdb:1) p @env["rack.request.form_input"].object_id
70289039522540
(rdb:1) p @env["rack.input"]
#<File:/var/folders/_c/0c66qtcm8xjcns006s6bhgzr0000gn/T/thin-body20120604-68121-12dpbf1>
(rdb:1) p @env["rack.input"].object_id
70289039522540
(rdb:1) p @env["rack.request.form_input"] == @env["rack.input"]
true
(rdb:1) p @env["rack.request.form_input"].eql?(@env["rack.input"])
false

So, == returns that the operands, which are the same Tempfile, are 
equivlent, but .eql? returns false.

I have a couple questions...

1) Anyone have any idea what might cause this?
2) What controls whether a StringIO or Tempfile is created when parsing a 
request object?

Thanks!

dave

[-- Attachment #2: Type: text/html, Size: 2370 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-06-05 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-05 17:05 .eql? returns false on identity comparison of Tempfiles David LaMacchia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).