[BUG/PATCH] cgi/session.rb, cgi/session/pstore.rb

ruby

    Next

  • 1. Seeking info on keyword parameters
    Will 2.0 make the names of keyword parameters available via reflection? Sorry to ask this again, but it is really important for me. I decided years ago that I much prefer 1) helper.move desk from: kitchen to: study using: trolley before: tomorrow to 2) helper.move_from_to_using_before(desk, kitchen, study, trolley, tomorrow) which is arguably somewhat better than 3) helper.move(desk, kitchen, study, trolley, tomorrow) So I am very concerned about keyword parameter names being available to reflection. Separately but related: will keyword parameter names be treated as part of the method names for method lookup, allowing a form of overloading? Could anyone shed some light on the plans here? Thanks.
  • 2. [SOLUTION] Ruby Quiz #14 LCD Numbers ( solution #2 )
    Wow ... Jannis Harder's solution is really short .... This is base on Jannis Harder's solution (398 bytes) ... We could make Jannis Harder's solution even shorter, for example: (1) y.map!{|v|v<<32} could rewrite to y.map!{|v|v<<f} ==> save 1 byte (2) many ?: code like ?x: y could rewrite to ?x:y ( no need space before y) ==> save n bytes (3) and ... (see my code about my idea to make it even shorter ) Here is my even shorter solution ( base on Jannis Harder's solution ) it is 349 bytes ( 49 bytes shorter than Jannis Harder's solution ) s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2) i=$*.join.split("").map{|x|x.to_i} d,="7krtt1r30v/s".unpack("m")[0].unpack("B*") f=" " a,b=f*s,f+"-"*s+f c,e,o="|",a+f+f,49 y=([0]*5).map{""} i.each{|z|u=d[z*7,7] 3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f} [1,3].each{|x|y[x]<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<0 ?f:c)<<f}} y[1,1]*=s y[2+s,1]*=s puts y

Re: [BUG/PATCH] cgi/session.rb, cgi/session/pstore.rb

Postby Ara.T.Howard » Thu, 15 Sep 2005 12:23:52 GMT




CGI::Session::MemoryStore and CGI::Session::PStore suffer from same issue...
updated patches (in the right order this time):


--- ./cgi/session.rb.org        2005-09-13 20:52:14.000000000 -0600
+++ ./cgi/session.rb    2005-09-13 21:13:22.000000000 -0600
@@ -244,7 +244,7 @@
      #   end
      #
      def initialize(request, option={})
-      @new_session = false
+      @new_session = nil
        session_key = option['session_key'] || '_session_id'
        session_id = option['session_id']
        unless session_id
@@ -381,10 +381,11 @@
          md5 = Digest::MD5.hexdigest(id)[0,16]
         @path = dir+"/"+prefix+md5+suffix
         unless File::exist? @path
-          unless session.new_session
+          unless session.new_session.nil?
              raise CGI::Session::NoSession, "uninitialized session"
            end
           @hash = {}
+          update
         end
        end

@@ -451,7 +452,7 @@
        def initialize(session, option=nil)
         @session_id = session.session_id
          unless GLOBAL_HASH_TABLE.key?(@session_id)
-          unless session.new_session
+          unless session.new_session.nil?
              raise CGI::Session::NoSession, "uninitialized session"
            end
            GLOBAL_HASH_TABLE[@session_id] = {}




--- ./cgi/session/pstore.rb.org 2005-09-13 21:07:52.000000000 -0600
+++ ./cgi/session/pstore.rb     2005-09-13 21:18:21.000000000 -0600
@@ -9,7 +9,7 @@
  # persistent of session data on top of the pstore library.  See
  # cgi/session.rb for more details on session storage managers.

-require 'cgi/session'
+require './cgi/session'
  require 'pstore'

  class CGI
@@ -62,7 +62,7 @@
         path = dir+"/"+prefix+md5
         path.untaint
         unless File::exist?(path)
-          unless session.new_session
+          unless session.new_session.nil?
              raise CGI::Session::NoSession, "uninitialized session"
            end
           @hash = {}


now i'm noticing that the create of session is not atomic... but that's for
another day.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================




Re: [BUG/PATCH] cgi/session.rb, cgi/session/pstore.rb

Postby nobuyoshi nakada » Thu, 15 Sep 2005 12:42:40 GMT

Hi,

At Wed, 14 Sep 2005 12:23:52 +0900,
Ara.T.Howard wrote in [ruby-talk:156036]:

What does this change?


Library starts with "./" directs `require' to load from
current working directory.  I guess this isn't intended
change.

-- 
Nobu Nakada



Re: [BUG/PATCH] cgi/session.rb, cgi/session/pstore.rb

Postby Ara.T.Howard » Thu, 15 Sep 2005 14:57:02 GMT




that's right - too tired - going to bed ;-(

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================




Similar Threads:

1.[BUG/PATCH] cgi/session.rb (SOLVED?)

2.[BUG/PATCH] cgi/session.rb

the following program with fail both the way it is, and using the commented
section:


   ~ > cat a.cgi
   #! /usr/local/bin/ruby

   require 'cgi'
   require 'cgi/session'

   cgi = CGI::new

   database_manager = CGI::Session::FileStore

   session =
   =begin
     begin
       s = CGI::Session::new cgi, 'database_manager' => database_manager, 'new_session' => false
       s.delete
       s
     rescue ArgumentError
       CGI::Session::new cgi, 'database_manager' => database_manager, 'new_session' => true
     end
   =end
       CGI::Session::new cgi, 'database_manager' => database_manager

   session.close

   this_time = Time::now
   last_time = session['last_time'] || this_time
   session['last_time'] = this_time
   session.close

   content = ''
   content << "<hr> THIS_TIME @ <b>#{ this_time }</b> <hr>"
   content << "<hr> LAST_TIME @ <b>#{ last_time }</b> <hr>"

   cgi.out{ content }


in either case a new session is __always__ created.  the docs say:

..
   # A CGI::Session instance is created from a CGI object.  By default,
   # this CGI::Session instance will start a new session if none currently
   # exists, or continue the current session for this client if one does
   # exist.  The +new_session+ option can be used to either always or
   # never create a new session.  See #new() for more details.
..

so there is no way to re-use a session attm.  this seems serious.  i think this
patch addresses the issue:


[ahoward@localhost build/ruby-1.8.2/lib/] diff -u -b -B cgi/session.rb.org cgi/session.rb
--- cgi/session.rb.org  2005-09-13 20:52:14.000000000 -0600
+++ cgi/session.rb      2005-09-13 20:53:32.000000000 -0600
@@ -244,7 +244,7 @@
      #   end
      #
      def initialize(request, option={})
-      @new_session = false
+      @new_session = nil
        session_key = option['session_key'] || '_session_id'
        session_id = option['session_id']
        unless session_id
@@ -381,10 +381,11 @@
          md5 = Digest::MD5.hexdigest(id)[0,16]
         @path = dir+"/"+prefix+md5+suffix
         unless File::exist? @path
-          unless session.new_session
+          unless session.new_session.nil?
              raise CGI::Session::NoSession, "uninitialized session"
            end
           @hash = {}
+          update
         end
        end


and, indeed, with the change the following works as expected/doccumented:

   #! /usr/local/bin/ruby
   require 'cgi'
   require './cgi/session'

   cgi = CGI::new
   content = ''
   database_manager = CGI::Session::FileStore
   this_time = Time::now

   begin
     session = CGI::Session::new cgi, 'database_manager' => database_manager
     last_time = session['last_time'] || this_time
     session['last_time'] = this_time
     session.close

     content << "<hr> THIS_TIME @ <b>#{ this_time }</b> <hr>"
     content << "<hr> LAST_TIME @ <b>#{ last_time }</b> <hr>"
   rescue Exception => e
     m, c, b = e.message, e.class, e.backtrace.join("\n")
     content << "<pre>#{ m } (#{ c })\n#{ b }</pre>"
   end
   cgi.out{ content }


hopefully this hasn't already been fixed - i searched for a while....

regards.


-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================



3.Sessions and GET (CGI.rb)

4.multipart forms and cgi - cgi.rb bug?

Hi Robert,

>
> Maybe the output is truncated.  Maybe you you didn't enter a file name
> before submitting the form. ...
>
> Kind regards
>
>     robert
>
>

There seems to be a bug in version 1.63 of cgi.rb when it comes to
multipart forms. After trying every combination of cgi['formname'],
cgi.param['formname'] etc it turns out it was only passing the first field
in the form.

I downloaded version 1.56 of cgi.rb from the cvs repository and replaced
1.63 and the multipart form now works correctly.

regards,

Martin



5.cgi/session , deleting old sessions.

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

7. Bug in cgi/session

8. BUG: CGI.Session on Windows



Return to ruby

 

Who is online

Users browsing this forum: No registered users and 44 guest