* lib/cgi/session.rb (FileStore): use marshalized data.
* test/cgi/session_dir: add a session directory in test. * test/cgi/test_cgi_session.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
274c3b94bf
commit
26862c00e9
@ -1,3 +1,11 @@
|
|||||||
|
Sat Nov 8 23:47:45 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi/session.rb (FileStore): use marshalized data.
|
||||||
|
|
||||||
|
* test/cgi/session_dir: add a session directory in test.
|
||||||
|
|
||||||
|
* test/cgi/test_cgi_session.rb: add a test.
|
||||||
|
|
||||||
Sat Nov 8 21:57:03 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
Sat Nov 8 21:57:03 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||||
|
|
||||||
* lib/cgi/session.rb: remove debug code.
|
* lib/cgi/session.rb: remove debug code.
|
||||||
|
@ -404,7 +404,7 @@ class CGI
|
|||||||
for line in f
|
for line in f
|
||||||
line.chomp!
|
line.chomp!
|
||||||
k, v = line.split('=',2)
|
k, v = line.split('=',2)
|
||||||
@hash[CGI::unescape(k)] = CGI::unescape(v)
|
@hash[CGI::unescape(k)] = Marshal.restore(CGI::unescape(v))
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
f.close unless f.nil?
|
f.close unless f.nil?
|
||||||
@ -422,7 +422,7 @@ class CGI
|
|||||||
lockf.flock File::LOCK_EX
|
lockf.flock File::LOCK_EX
|
||||||
f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
|
f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
|
||||||
for k,v in @hash
|
for k,v in @hash
|
||||||
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(v))
|
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(Marshal.dump(v)))
|
||||||
end
|
end
|
||||||
f.close
|
f.close
|
||||||
File.rename @path+".new", @path
|
File.rename @path+".new", @path
|
||||||
|
59
test/cgi/test_cgi_session.rb
Executable file
59
test/cgi/test_cgi_session.rb
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
require 'test/unit'
|
||||||
|
require 'cgi'
|
||||||
|
require 'cgi/session'
|
||||||
|
require 'stringio'
|
||||||
|
def d(obj)
|
||||||
|
STDERR.write(obj.inspect+"\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
class CGISessionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
|
||||||
|
def setup
|
||||||
|
FileUtils.rm(Dir::glob(File.dirname(__FILE__)+"/session_dir/*"))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
@environ.each do |key, val| ENV.delete(key) end
|
||||||
|
$stdout = STDOUT
|
||||||
|
# FileUtils.rm(Dir::glob(File.dirname(__FILE__)+"/session_dir/*"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_cgi_session_core
|
||||||
|
@environ = {
|
||||||
|
'REQUEST_METHOD' => 'GET',
|
||||||
|
# 'QUERY_STRING' => 'id=123&id=456&id=&str=%40h+%3D%7E+%2F%5E%24%2F',
|
||||||
|
# 'HTTP_COOKIE' => '_session_id=12345; name1=val1&val2;',
|
||||||
|
'SERVER_SOFTWARE' => 'Apache 2.2.0',
|
||||||
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
|
}
|
||||||
|
ENV.update(@environ)
|
||||||
|
cgi = CGI.new
|
||||||
|
session = CGI::Session.new(cgi,"tmpdir"=>File.dirname(__FILE__)+"/session_dir")
|
||||||
|
session["key1"]="value1"
|
||||||
|
session["key2"]="\x8F\xBC\x8D]".force_encoding("SJIS")
|
||||||
|
assert_equal("value1",session["key1"])
|
||||||
|
assert_equal("\x8F\xBC\x8D]".force_encoding("SJIS"),session["key2"])
|
||||||
|
session.close
|
||||||
|
$stdout = StringIO.new
|
||||||
|
cgi.out{""}
|
||||||
|
|
||||||
|
@environ = {
|
||||||
|
'REQUEST_METHOD' => 'GET',
|
||||||
|
# 'HTTP_COOKIE' => "_session_id=#{session_id}",
|
||||||
|
'QUERY_STRING' => "_session_id=#{session.session_id}",
|
||||||
|
'SERVER_SOFTWARE' => 'Apache 2.2.0',
|
||||||
|
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
||||||
|
}
|
||||||
|
ENV.update(@environ)
|
||||||
|
cgi = CGI.new
|
||||||
|
session = CGI::Session.new(cgi,"tmpdir"=>File.dirname(__FILE__)+"/session_dir")
|
||||||
|
$stdout = StringIO.new
|
||||||
|
assert_equal("value1",session["key1"])
|
||||||
|
assert_equal("\x8F\xBC\x8D]".force_encoding("SJIS"),session["key2"])
|
||||||
|
session.close
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user