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.

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

-- 

 ====================================
 | 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
 ====================================