Bug in CGI::Session?

Hello,

The following doesn’t work anymore with the latest CVS version of Ruby 1.8:

···

require 'cgi’
require ‘cgi/session’

cgi = CGI.new
session = CGI::Session.new(cgi)

fg@tkp:~$ ruby test.rb
(offline mode: enter name=value pairs on standard input)
/usr/local/lib/ruby/1.8/cgi.rb:947:in dup': can't dup NilClass (TypeError) from /usr/local/lib/ruby/1.8/cgi.rb:947:into_ary’
from /usr/local/lib/ruby/1.8/cgi/session.rb:37:in initialize' from test.rb:7:innew’
from test.rb:7

Looks like the bug follows the changes on CGI#[] done on Dec 28th.

What makes me love Ruby is the short term solution:

class NilClass
def dup
nil
end
end
… and my 12000 lines cgi script works again :wink:

Francois

PS: BTW, why nil.dup is illegal by default ?

Hi,

···

In message “Bug in CGI::Session ?” on 03/01/17, Francois Goret fg@siamecommerce.com writes:

The following doesn’t work anymore with the latest CVS version of Ruby 1.8:

require ‘cgi’
require ‘cgi/session’

cgi = CGI.new
session = CGI::Session.new(cgi)

fg@tkp:~$ ruby test.rb
(offline mode: enter name=value pairs on standard input)
/usr/local/lib/ruby/1.8/cgi.rb:947:in dup': can't dup NilClass (TypeError) from /usr/local/lib/ruby/1.8/cgi.rb:947:in to_ary’
from /usr/local/lib/ruby/1.8/cgi/session.rb:37:in initialize' from test.rb:7:in new’
from test.rb:7

Looks like the bug follows the changes on CGI# done on Dec 28th.

Thank you for pointing out. I will fix this soon.

						matz.

there is also still the issue that in lib/cgi/session.rb:77-85 the = method
prevents user defined session managers to store anything but Strings in there
sessions, eg :

 77     def []=(key, val)
 78       unless @write_lock
 79         @write_lock = true
 80       end
 81       unless @data
 82         @data = @dbman.restore
 83       end
 84       @data[key] = String(val)
 85     end

in my own code i’ve done

  • @data[key] = String(val)
  • @data[key] = val

which has allowed me to write a session::pstore class which stores any type of
object.

if this were changed and MemoryStore and FileStore cast val to String the
changes would be backward compatible while still allowing development of user
defined sessions which store more than strings.

-a

···

On Fri, 17 Jan 2003, Yukihiro Matsumoto wrote:

Hi,

In message “Bug in CGI::Session ?” > on 03/01/17, Francois Goret fg@siamecommerce.com writes:

The following doesn’t work anymore with the latest CVS version of Ruby 1.8:

require ‘cgi’
require ‘cgi/session’

cgi = CGI.new
session = CGI::Session.new(cgi)

fg@tkp:~$ ruby test.rb
(offline mode: enter name=value pairs on standard input)
/usr/local/lib/ruby/1.8/cgi.rb:947:in dup': can't dup NilClass (TypeError) from /usr/local/lib/ruby/1.8/cgi.rb:947:in to_ary’
from /usr/local/lib/ruby/1.8/cgi/session.rb:37:in initialize' from test.rb:7:in new’
from test.rb:7

Looks like the bug follows the changes on CGI# done on Dec 28th.

Thank you for pointing out. I will fix this soon.

  					matz.

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hi,

···

In message “Re: Bug in CGI::Session ?” on 03/01/18, ahoward ahoward@fsl.noaa.gov writes:

there is also still the issue that in lib/cgi/session.rb:77-85 the = method
prevents user defined session managers to store anything but Strings in there
sessions, eg :

This is fixed in 1.8.0pre1.

						matz.