StringIO#binmode: bug in cgi.rb and yaml.rb

Sorry if Ruby 1.6 is an ancient history for some, but I still see a
point in reporting bugs related to it.

It took me a while to figure out why file upload didn’t want to work at
all in Samizdat. What I found was a misunderstanding between yaml.rb,
which defines a limited StringIO class without ‘binmode’ method, and
cgi.rb, which assumes that if there is StringIO class, it has a
’binmode’ method.

As a result, I receive following error whenever I upload a file:

/usr/lib/ruby/1.6/cgi.rb:653:in read_multipart': undefined methodbinmode’ for
#StringIO:0x404a89e4 (NameError)
from /usr/lib/ruby/1.6/cgi.rb:744:in initialize_query' from /usr/lib/ruby/1.6/cgi.rb:1587:ininitialize’

Offending code in cgi.rb:

    if 10240 < content_length
      require "tempfile"
      body = Tempfile.new("CGI")
    else
      begin
        require "stringio" if not defined? StringIO
        body = StringIO.new
      rescue LoadError
        require "tempfile"
        body = Tempfile.new("CGI")
      end
    end
    body.binmode

A dirty workaround I had to use:

if defined? StringIO and
not StringIO.instance_methods(true).include? ‘binmode’ then
class StringIO
def binmode
end
end
end

I think it is a bug both in yaml.rb, which should at least define (if
not implement, or inherit, or borrow somewhere) all methods found in
standard StringIO from Ruby 1.8, and in cgi.rb, which should check for
body.type.instance_methods(true).include? ‘binmode’.

···


Dmitry Borodaenko

Hi,

···

At Thu, 21 Aug 2003 02:50:11 +0900, Dmitry Borodaenko wrote:

It took me a while to figure out why file upload didn’t want to work at
all in Samizdat. What I found was a misunderstanding between yaml.rb,
which defines a limited StringIO class without ‘binmode’ method, and
cgi.rb, which assumes that if there is StringIO class, it has a
‘binmode’ method.

Latest StringIO (in shim for 1.6) has #binmode.
http://raa.ruby-lang.org/list.rhtml?name=shim-ruby16_18


Nobu Nakada

Thanks, requiring ‘stringio’ from Shim helped. BTW replacing cgi.rb with
one from Ruby 1.8 has the same effect, since it unconditionally requires
‘stringio’ and thus overwrites limited substitute from yaml.rb: can this
change be applied to the next point release of Ruby 1.6?

However, that wasn’t the end of my trouble with cgi.rb read_multipart.
Now I can’t upload file that is bigger than 19746 bytes, I suspect that
this has to do with switching from Tempfile to StringIO on the second
run of “until -1 == content_length” loop. It’s late here in Minsk, so
I’ll leave it until tomorrow to dig this deeper, if no one comes up with
a ready fix by then…

···

On Thu, Aug 21, 2003 at 11:18:49AM +0900, nobu.nokada@softhome.net wrote:

Latest StringIO (in shim for 1.6) has #binmode.
http://raa.ruby-lang.org/list.rhtml?name=shim-ruby16_18


Dmitry Borodaenko

Hi,

···

At Sat, 23 Aug 2003 04:06:02 +0900, Dmitry Borodaenko wrote:

Thanks, requiring ‘stringio’ from Shim helped. BTW replacing cgi.rb with
one from Ruby 1.8 has the same effect, since it unconditionally requires
‘stringio’ and thus overwrites limited substitute from yaml.rb: can this
change be applied to the next point release of Ruby 1.6?

Since 1.6 had ended, it won’t be released more, matz said.


Nobu Nakada