mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/cgi.rb (CGI::Cookie): remove delagate.
* test/cgi/test_cgi_cookie.rb: added for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1366802a1f
commit
19b25eb670
3 changed files with 114 additions and 4 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Aug 27 10:34:42 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/cgi.rb (CGI::Cookie): remove delagate.
|
||||||
|
|
||||||
|
* test/cgi/test_cgi_cookie.rb: added for above.
|
||||||
|
|
||||||
Wed Aug 27 01:13:54 2008 Tanaka Akira <akr@fsij.org>
|
Wed Aug 27 01:13:54 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* transcode.c (transcode_loop): simplified.
|
* transcode.c (transcode_loop): simplified.
|
||||||
|
|
|
@ -749,9 +749,6 @@ class CGI
|
||||||
stdoutput.print(*options)
|
stdoutput.print(*options)
|
||||||
end
|
end
|
||||||
|
|
||||||
require "delegate"
|
|
||||||
|
|
||||||
# Class representing an HTTP cookie.
|
|
||||||
#
|
#
|
||||||
# In addition to its specific fields and methods, a Cookie instance
|
# In addition to its specific fields and methods, a Cookie instance
|
||||||
# is a delegator to the array of its values.
|
# is a delegator to the array of its values.
|
||||||
|
@ -784,7 +781,7 @@ class CGI
|
||||||
# cookie1.domain = 'domain'
|
# cookie1.domain = 'domain'
|
||||||
# cookie1.expires = Time.now + 30
|
# cookie1.expires = Time.now + 30
|
||||||
# cookie1.secure = true
|
# cookie1.secure = true
|
||||||
class Cookie < DelegateClass(Array)
|
class Cookie < Array
|
||||||
|
|
||||||
# Create a new CGI::Cookie object.
|
# Create a new CGI::Cookie object.
|
||||||
#
|
#
|
||||||
|
|
107
test/cgi/test_cgi_cookie.rb
Normal file
107
test/cgi/test_cgi_cookie.rb
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
require 'test/unit'
|
||||||
|
require 'cgi'
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
|
|
||||||
|
class CGICookieTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
|
||||||
|
def setup
|
||||||
|
ENV['REQUEST_METHOD'] = 'GET'
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
%W[REQUEST_METHOD SCRIPT_NAME].each do |name|
|
||||||
|
ENV.delete(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_cgi_cookie_new_simple
|
||||||
|
cookie = CGI::Cookie.new('name1', 'val1', '&<>"', "\245\340\245\271\245\253")
|
||||||
|
assert_equal('name1', cookie.name)
|
||||||
|
assert_equal(['val1', '&<>"', "\245\340\245\271\245\253"], cookie.value)
|
||||||
|
assert_nil(cookie.domain)
|
||||||
|
assert_nil(cookie.expires)
|
||||||
|
assert_equal('', cookie.path)
|
||||||
|
assert_equal(false, cookie.secure)
|
||||||
|
assert_equal("name1=val1&%26%3C%3E%22&%A5%E0%A5%B9%A5%AB; path=", cookie.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_cgi_cookie_new_complex
|
||||||
|
t = Time.gm(2030, 12, 31, 23, 59, 59)
|
||||||
|
value = ['val1', '&<>"', "\245\340\245\271\245\253"]
|
||||||
|
cookie = CGI::Cookie.new('name'=>'name1',
|
||||||
|
'value'=>value,
|
||||||
|
'path'=>'/cgi-bin/myapp/',
|
||||||
|
'domain'=>'www.example.com',
|
||||||
|
'expires'=>t,
|
||||||
|
'secure'=>true
|
||||||
|
)
|
||||||
|
assert_equal('name1', cookie.name)
|
||||||
|
assert_equal(value, cookie.value)
|
||||||
|
assert_equal('www.example.com', cookie.domain)
|
||||||
|
assert_equal(t, cookie.expires)
|
||||||
|
assert_equal('/cgi-bin/myapp/', cookie.path)
|
||||||
|
assert_equal(true, cookie.secure)
|
||||||
|
assert_equal('name1=val1&%26%3C%3E%22&%A5%E0%A5%B9%A5%AB; domain=www.example.com; path=/cgi-bin/myapp/; expires=Tue, 31 Dec 2030 23:59:59 GMT; secure', cookie.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_cgi_cookie_scriptname
|
||||||
|
cookie = CGI::Cookie.new('name1', 'value1')
|
||||||
|
assert_equal('', cookie.path)
|
||||||
|
cookie = CGI::Cookie.new('name'=>'name1', 'value'=>'value1')
|
||||||
|
assert_equal('', cookie.path)
|
||||||
|
## when ENV['SCRIPT_NAME'] is set, cookie.path is set automatically
|
||||||
|
ENV['SCRIPT_NAME'] = '/cgi-bin/app/example.cgi'
|
||||||
|
cookie = CGI::Cookie.new('name1', 'value1')
|
||||||
|
assert_equal('/cgi-bin/app/', cookie.path)
|
||||||
|
cookie = CGI::Cookie.new('name'=>'name1', 'value'=>'value1')
|
||||||
|
assert_equal('/cgi-bin/app/', cookie.path)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_cgi_cookie_parse
|
||||||
|
## ';' separator
|
||||||
|
cookie_str = 'name1=val1&val2; name2=val2&%26%3C%3E%22;_session_id=12345'
|
||||||
|
cookies = CGI::Cookie.parse(cookie_str)
|
||||||
|
list = [
|
||||||
|
['name1', ['val1', 'val2']],
|
||||||
|
['name2', ['val2', '&<>"']],
|
||||||
|
['_session_id', ['12345']],
|
||||||
|
]
|
||||||
|
list.each do |name, value|
|
||||||
|
cookie = cookies[name]
|
||||||
|
assert_equal(name, cookie.name)
|
||||||
|
assert_equal(value, cookie.value)
|
||||||
|
end
|
||||||
|
## ',' separator
|
||||||
|
cookie_str = 'name1=val1&val2, name2=val2&%26%3C%3E%22,_session_id=12345'
|
||||||
|
cookies = CGI::Cookie.parse(cookie_str)
|
||||||
|
list.each do |name, value|
|
||||||
|
cookie = cookies[name]
|
||||||
|
assert_equal(name, cookie.name)
|
||||||
|
assert_equal(value, cookie.value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_cgi_cookie_arrayinterface
|
||||||
|
cookie = CGI::Cookie.new('name1', 'a', 'b', 'c')
|
||||||
|
assert_equal('a', cookie[0])
|
||||||
|
assert_equal('c', cookie[2])
|
||||||
|
assert_nil(cookie[3])
|
||||||
|
assert_equal('a', cookie.first)
|
||||||
|
assert_equal('c', cookie.last)
|
||||||
|
assert_equal(['A', 'B', 'C'], cookie.collect{|e| e.upcase})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
instance_methods.each do |method|
|
||||||
|
private method if method =~ /^test_(.*)/ && $1 != ENV['TEST']
|
||||||
|
end if ENV['TEST']
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue