rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: David LaMacchia <dml@copious.com>
To: rack-devel@googlegroups.com
Subject: .eql? returns false on identity comparison of Tempfiles
Date: Tue, 5 Jun 2012 10:05:00 -0700 (PDT)	[thread overview]
Message-ID: <f19ec3dd-85ea-4111-a610-b3182fae85c9@googlegroups.com> (raw)

[-- 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 --]

                 reply	other threads:[~2012-06-05 17:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f19ec3dd-85ea-4111-a610-b3182fae85c9@googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).