diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-15 01:54:40 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-15 01:54:40 +0000 |
commit | 1c474bb43e7bef7af8d0b3857d2bbbafa53d87f7 (patch) | |
tree | 65e5b11627653d6cc3c5fe49f62b5b1c6899fdd5 /lib | |
parent | 6add16fdf5dfbca9c2692e0f05e17b35aa497f05 (diff) | |
download | ruby-1c474bb43e7bef7af8d0b3857d2bbbafa53d87f7.tar.gz ruby-1c474bb43e7bef7af8d0b3857d2bbbafa53d87f7.tar.xz ruby-1c474bb43e7bef7af8d0b3857d2bbbafa53d87f7.zip |
* ext/openssl/ossl_digest.c (ossl_digest_initialize): [ruby-dev:25198]
* lib/cgi/session.rb (CGI::Session::initialize): generate new
session if given session_id does not exist. [ruby-list:40368]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cgi/session.rb | 43 | ||||
-rw-r--r-- | lib/cgi/session/pstore.rb | 2 | ||||
-rw-r--r-- | lib/jcode.rb | 2 |
3 files changed, 28 insertions, 19 deletions
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb index 1c493546f..50abf3213 100644 --- a/lib/cgi/session.rb +++ b/lib/cgi/session.rb @@ -155,6 +155,9 @@ class CGI # class Session + #:nodoc: + class NoSession < RuntimeError; end + # The id of this session. attr_reader :session_id, :new_session @@ -243,35 +246,43 @@ class CGI def initialize(request, option={}) @new_session = false session_key = option['session_key'] || '_session_id' - id = option['session_id'] - unless id + session_id = option['session_id'] + unless session_id if option['new_session'] - id = create_new_id + session_id = create_new_id end end - unless id + unless session_id if request.key?(session_key) - id = request[session_key] - id = id.read if id.respond_to?(:read) + session_id = request[session_key] + session_id = session_id.read if session_id.respond_to?(:read) end - unless id - id, = request.cookies[session_key] + unless session_id + session_id, = request.cookies[session_key] end - unless id + unless session_id if option.key?('new_session') and not option['new_session'] raise ArgumentError, "session_key `%s' should be supplied"%session_key end - id = create_new_id + session_id = create_new_id end end - @session_id = id + @session_id = session_id dbman = option['database_manager'] || FileStore - @dbman = dbman::new(self, option) + begin + @dbman = dbman::new(self, option) + rescue NoSession + if option.key?('new_session') and not option['new_session'] + raise ArgumentError, "invalid session_id `%s'"%session_id + end + session_id = @session_id = create_new_id + retry + end request.instance_eval do - @output_hidden = {session_key => id} + @output_hidden = {session_key => session_id} @output_cookies = [ Cookie::new("name" => session_key, - "value" => id, + "value" => session_id, "expires" => option['session_expires'], "domain" => option['session_domain'], "secure" => option['session_secure'], @@ -371,7 +382,7 @@ class CGI @path = dir+"/"+prefix+md5+suffix unless File::exist? @path unless session.new_session - raise RuntimeError, "uninitialized session" + raise CGI::Session::NoSession, "uninitialized session" end @hash = {} end @@ -441,7 +452,7 @@ class CGI @session_id = session.session_id unless GLOBAL_HASH_TABLE.key?(@session_id) unless session.new_session - raise RuntimeError, "uninitialized session" + raise CGI::Session::NoSession, "uninitialized session" end GLOBAL_HASH_TABLE[@session_id] = {} end diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb index e65a2a97d..696f6f2d3 100644 --- a/lib/cgi/session/pstore.rb +++ b/lib/cgi/session/pstore.rb @@ -63,7 +63,7 @@ class CGI path.untaint unless File::exist?(path) unless session.new_session - raise RuntimeError, "uninitialized session" + raise CGI::Session::NoSession, "uninitialized session" end @hash = {} end diff --git a/lib/jcode.rb b/lib/jcode.rb index efb21af33..691d22daf 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -91,9 +91,7 @@ class String def succ str = self.dup - p [self.object_id, str.object_id] str.succ! or str -# (str = self.dup).succ! or str end private |