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

D

Dmitry Borodaenko

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 method
`binmode' 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:in `initialize'

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'.
 
D

Dmitry Borodaenko

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

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...
 
N

Nobuyoshi Nakada

Hi,

At Sat, 23 Aug 2003 04:06:02 +0900,
Dmitry said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top