rubysl-cgi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/cgi.rb +1 -0
- data/lib/rubysl/cgi.rb +2 -0
- data/lib/rubysl/cgi/cgi.rb +2333 -0
- data/lib/rubysl/cgi/version.rb +5 -0
- data/rubysl-cgi.gemspec +23 -0
- data/spec/cookie/domain_spec.rb +22 -0
- data/spec/cookie/expires_spec.rb +22 -0
- data/spec/cookie/initialize_spec.rb +146 -0
- data/spec/cookie/name_spec.rb +22 -0
- data/spec/cookie/parse_spec.rb +17 -0
- data/spec/cookie/path_spec.rb +22 -0
- data/spec/cookie/secure_spec.rb +69 -0
- data/spec/cookie/to_s_spec.rb +28 -0
- data/spec/cookie/value_spec.rb +79 -0
- data/spec/escapeElement_spec.rb +19 -0
- data/spec/escapeHTML_spec.rb +25 -0
- data/spec/escape_spec.rb +13 -0
- data/spec/header_spec.rb +7 -0
- data/spec/htmlextension/a_spec.rb +48 -0
- data/spec/htmlextension/base_spec.rb +32 -0
- data/spec/htmlextension/blockquote_spec.rb +32 -0
- data/spec/htmlextension/br_spec.rb +21 -0
- data/spec/htmlextension/caption_spec.rb +32 -0
- data/spec/htmlextension/checkbox_group_spec.rb +77 -0
- data/spec/htmlextension/checkbox_spec.rb +76 -0
- data/spec/htmlextension/doctype_spec.rb +26 -0
- data/spec/htmlextension/file_field_spec.rb +73 -0
- data/spec/htmlextension/fixtures/common.rb +16 -0
- data/spec/htmlextension/form_spec.rb +57 -0
- data/spec/htmlextension/frame_spec.rb +13 -0
- data/spec/htmlextension/frameset_spec.rb +13 -0
- data/spec/htmlextension/hidden_spec.rb +58 -0
- data/spec/htmlextension/html_spec.rb +65 -0
- data/spec/htmlextension/image_button_spec.rb +68 -0
- data/spec/htmlextension/img_spec.rb +84 -0
- data/spec/htmlextension/multipart_form_spec.rb +63 -0
- data/spec/htmlextension/password_field_spec.rb +83 -0
- data/spec/htmlextension/popup_menu_spec.rb +7 -0
- data/spec/htmlextension/radio_button_spec.rb +76 -0
- data/spec/htmlextension/radio_group_spec.rb +78 -0
- data/spec/htmlextension/reset_spec.rb +56 -0
- data/spec/htmlextension/scrolling_list_spec.rb +7 -0
- data/spec/htmlextension/shared/popup_menu.rb +94 -0
- data/spec/htmlextension/submit_spec.rb +56 -0
- data/spec/htmlextension/text_field_spec.rb +83 -0
- data/spec/htmlextension/textarea_spec.rb +72 -0
- data/spec/http_header_spec.rb +9 -0
- data/spec/initialize_spec.rb +171 -0
- data/spec/out_spec.rb +50 -0
- data/spec/parse_spec.rb +23 -0
- data/spec/pretty_spec.rb +23 -0
- data/spec/print_spec.rb +25 -0
- data/spec/queryextension/accept_charset_spec.rb +21 -0
- data/spec/queryextension/accept_encoding_spec.rb +21 -0
- data/spec/queryextension/accept_language_spec.rb +21 -0
- data/spec/queryextension/accept_spec.rb +21 -0
- data/spec/queryextension/auth_type_spec.rb +21 -0
- data/spec/queryextension/cache_control_spec.rb +21 -0
- data/spec/queryextension/content_length_spec.rb +25 -0
- data/spec/queryextension/content_type_spec.rb +21 -0
- data/spec/queryextension/cookies_spec.rb +9 -0
- data/spec/queryextension/element_reference_spec.rb +33 -0
- data/spec/queryextension/from_spec.rb +21 -0
- data/spec/queryextension/gateway_interface_spec.rb +21 -0
- data/spec/queryextension/has_key_spec.rb +6 -0
- data/spec/queryextension/host_spec.rb +21 -0
- data/spec/queryextension/include_spec.rb +6 -0
- data/spec/queryextension/key_spec.rb +6 -0
- data/spec/queryextension/keys_spec.rb +19 -0
- data/spec/queryextension/multipart_spec.rb +39 -0
- data/spec/queryextension/negotiate_spec.rb +21 -0
- data/spec/queryextension/params_spec.rb +44 -0
- data/spec/queryextension/path_info_spec.rb +21 -0
- data/spec/queryextension/path_translated_spec.rb +21 -0
- data/spec/queryextension/pragma_spec.rb +21 -0
- data/spec/queryextension/query_string_spec.rb +21 -0
- data/spec/queryextension/raw_cookie2_spec.rb +21 -0
- data/spec/queryextension/raw_cookie_spec.rb +21 -0
- data/spec/queryextension/referer_spec.rb +21 -0
- data/spec/queryextension/remote_addr_spec.rb +21 -0
- data/spec/queryextension/remote_host_spec.rb +21 -0
- data/spec/queryextension/remote_ident_spec.rb +21 -0
- data/spec/queryextension/remote_user_spec.rb +21 -0
- data/spec/queryextension/request_method_spec.rb +21 -0
- data/spec/queryextension/script_name_spec.rb +21 -0
- data/spec/queryextension/server_name_spec.rb +21 -0
- data/spec/queryextension/server_port_spec.rb +25 -0
- data/spec/queryextension/server_protocol_spec.rb +21 -0
- data/spec/queryextension/server_software_spec.rb +21 -0
- data/spec/queryextension/shared/has_key.rb +19 -0
- data/spec/queryextension/user_agent_spec.rb +21 -0
- data/spec/rfc1123_date_spec.rb +9 -0
- data/spec/shared/http_header.rb +111 -0
- data/spec/unescapeElement_spec.rb +19 -0
- data/spec/unescapeHTML_spec.rb +33 -0
- data/spec/unescape_spec.rb +14 -0
- metadata +293 -0
data/rubysl-cgi.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/cgi/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-cgi"
|
6
|
+
spec.version = RubySL::CGI::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library cgi.}
|
10
|
+
spec.summary = %q{Ruby standard library cgi.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-cgi"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#domain" do
|
4
|
+
it "returns self's domain" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.domain.should be_nil
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com")
|
9
|
+
cookie.domain.should == "example.com"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "CGI::Cookie#domain=" do
|
14
|
+
it "sets self's domain" do
|
15
|
+
cookie = CGI::Cookie.new("test-cookie")
|
16
|
+
cookie.domain = "test.com"
|
17
|
+
cookie.domain.should == "test.com"
|
18
|
+
|
19
|
+
cookie.domain = "example.com"
|
20
|
+
cookie.domain.should == "example.com"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#expires" do
|
4
|
+
it "returns self's expiration date" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.expires.should be_nil
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602))
|
9
|
+
cookie.expires.should == Time.at(1196524602)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "CGI::Cookie#expires=" do
|
14
|
+
it "sets self's expiration date" do
|
15
|
+
cookie = CGI::Cookie.new("test-cookie")
|
16
|
+
cookie.expires = Time.at(1196524602)
|
17
|
+
cookie.expires.should == Time.at(1196524602)
|
18
|
+
|
19
|
+
cookie.expires = Time.at(1196525000)
|
20
|
+
cookie.expires.should == Time.at(1196525000)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#initialize when passed String" do
|
4
|
+
before(:each) do
|
5
|
+
@cookie = CGI::Cookie.allocate
|
6
|
+
end
|
7
|
+
|
8
|
+
it "sets the self's name to the passed String" do
|
9
|
+
@cookie.send(:initialize, "test-cookie")
|
10
|
+
@cookie.name.should == "test-cookie"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the self's value to an empty Array" do
|
14
|
+
@cookie.send(:initialize, "test-cookie")
|
15
|
+
@cookie.value.should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets self to a non-secure cookie" do
|
19
|
+
@cookie.send(:initialize, "test")
|
20
|
+
@cookie.secure.should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do
|
24
|
+
@cookie.send(:initialize, "test-cookie")
|
25
|
+
@cookie.path.should == ""
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do
|
29
|
+
old_script_name = ENV["SCRIPT_NAME"]
|
30
|
+
|
31
|
+
begin
|
32
|
+
ENV["SCRIPT_NAME"] = "some/path/script.rb"
|
33
|
+
@cookie.send(:initialize, "test-cookie")
|
34
|
+
@cookie.path.should == "some/path/"
|
35
|
+
|
36
|
+
ENV["SCRIPT_NAME"] = "script.rb"
|
37
|
+
@cookie.send(:initialize, "test-cookie")
|
38
|
+
@cookie.path.should == ""
|
39
|
+
|
40
|
+
ENV["SCRIPT_NAME"] = nil
|
41
|
+
@cookie.send(:initialize, "test-cookie")
|
42
|
+
@cookie.path.should == ""
|
43
|
+
ensure
|
44
|
+
ENV["SCRIPT_NAME"] = old_script_name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "does not set self's expiration date" do
|
49
|
+
@cookie.expires.should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not set self's domain" do
|
53
|
+
@cookie.domain.should be_nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "CGI::Cookie#initialize when passed Hash" do
|
58
|
+
before(:each) do
|
59
|
+
@cookie = CGI::Cookie.allocate
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets self's contents based on the passed Hash" do
|
63
|
+
@cookie.send(:initialize,
|
64
|
+
'name' => 'test-cookie',
|
65
|
+
'value' => ["one", "two", "three"],
|
66
|
+
'path' => 'some/path/',
|
67
|
+
'domain' => 'example.com',
|
68
|
+
'expires' => Time.at(1196524602),
|
69
|
+
'secure' => true)
|
70
|
+
|
71
|
+
@cookie.name.should == "test-cookie"
|
72
|
+
@cookie.value.should == ["one", "two", "three"]
|
73
|
+
@cookie.path.should == "some/path/"
|
74
|
+
@cookie.domain.should == "example.com"
|
75
|
+
@cookie.expires.should == Time.at(1196524602)
|
76
|
+
@cookie.secure.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do
|
80
|
+
old_script_name = ENV["SCRIPT_NAME"]
|
81
|
+
|
82
|
+
begin
|
83
|
+
ENV["SCRIPT_NAME"] = "some/path/script.rb"
|
84
|
+
@cookie.send(:initialize, 'name' => 'test-cookie')
|
85
|
+
@cookie.path.should == "some/path/"
|
86
|
+
|
87
|
+
ENV["SCRIPT_NAME"] = "script.rb"
|
88
|
+
@cookie.send(:initialize, 'name' => 'test-cookie')
|
89
|
+
@cookie.path.should == ""
|
90
|
+
|
91
|
+
ENV["SCRIPT_NAME"] = nil
|
92
|
+
@cookie.send(:initialize, 'name' => 'test-cookie')
|
93
|
+
@cookie.path.should == ""
|
94
|
+
ensure
|
95
|
+
ENV["SCRIPT_NAME"] = old_script_name
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "tries to convert the Hash's 'value' to an Array using #Array" do
|
100
|
+
obj = mock("Converted To Array")
|
101
|
+
obj.should_receive(:to_ary).and_return(["1", "2", "3"])
|
102
|
+
@cookie.send(:initialize,
|
103
|
+
'name' => 'test-cookie',
|
104
|
+
'value' => obj)
|
105
|
+
@cookie.value.should == [ "1", "2", "3" ]
|
106
|
+
|
107
|
+
obj = mock("Converted To Array")
|
108
|
+
obj.should_receive(:to_a).and_return(["one", "two", "three"])
|
109
|
+
@cookie.send(:initialize,
|
110
|
+
'name' => 'test-cookie',
|
111
|
+
'value' => obj)
|
112
|
+
@cookie.value.should == [ "one", "two", "three" ]
|
113
|
+
|
114
|
+
obj = mock("Put into an Array")
|
115
|
+
@cookie.send(:initialize,
|
116
|
+
'name' => 'test-cookie',
|
117
|
+
'value' => obj)
|
118
|
+
@cookie.value.should == [ obj ]
|
119
|
+
end
|
120
|
+
|
121
|
+
it "raises a ArgumentError when the passed Hash has no 'name' entry" do
|
122
|
+
lambda { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError)
|
123
|
+
lambda { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "CGI::Cookie#initialize when passed String, values ..." do
|
128
|
+
before(:each) do
|
129
|
+
@cookie = CGI::Cookie.allocate
|
130
|
+
end
|
131
|
+
|
132
|
+
it "sets the self's name to the passed String" do
|
133
|
+
@cookie.send(:initialize, "test-cookie", "one", "two", "three")
|
134
|
+
@cookie.name.should == "test-cookie"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "sets the self's value to an Array containing all passed values" do
|
138
|
+
@cookie.send(:initialize, "test-cookie", "one", "two", "three")
|
139
|
+
@cookie.value.should == ["one", "two", "three"]
|
140
|
+
end
|
141
|
+
|
142
|
+
it "sets self to a non-secure cookie" do
|
143
|
+
@cookie.send(:initialize, "test", "one", "two", "three")
|
144
|
+
@cookie.secure.should be_false
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#name" do
|
4
|
+
it "returns self's name" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.name.should == "test-cookie"
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("name" => "another cookie")
|
9
|
+
cookie.name.should == "another cookie"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "CGI::Cookie#name=" do
|
14
|
+
it "sets self's expiration date" do
|
15
|
+
cookie = CGI::Cookie.new("test-cookie")
|
16
|
+
cookie.name = "another name"
|
17
|
+
cookie.name.should == "another name"
|
18
|
+
|
19
|
+
cookie.name = "and one more"
|
20
|
+
cookie.name.should == "and one more"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie.parse" do
|
4
|
+
it "parses a raw cookie string into a hash of Cookies" do
|
5
|
+
expected = { "test-cookie" => ["one", "two", "three"] }
|
6
|
+
CGI::Cookie.parse("test-cookie=one&two&three").should == expected
|
7
|
+
|
8
|
+
expected = { "second cookie" => ["three", "four"], "first cookie" => ["one", "two"] }
|
9
|
+
CGI::Cookie.parse("first cookie=one&two;second cookie=three&four").should == expected
|
10
|
+
end
|
11
|
+
|
12
|
+
it "unescapes the Cookie values" do
|
13
|
+
cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
|
14
|
+
expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] }
|
15
|
+
CGI::Cookie.parse(cookie).should == expected
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#path" do
|
4
|
+
it "returns self's path" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.path.should == ""
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/")
|
9
|
+
cookie.path.should == "/some/path/"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "CGI::Cookie#path=" do
|
14
|
+
it "sets self's path" do
|
15
|
+
cookie = CGI::Cookie.new("test-cookie")
|
16
|
+
cookie.path = "/some/path/"
|
17
|
+
cookie.path.should == "/some/path/"
|
18
|
+
|
19
|
+
cookie.path = "/another/path/"
|
20
|
+
cookie.path.should == "/another/path/"
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#secure" do
|
4
|
+
before(:each) do
|
5
|
+
@cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns whether self is a secure cookie or not" do
|
9
|
+
@cookie.secure = true
|
10
|
+
@cookie.secure.should be_true
|
11
|
+
|
12
|
+
@cookie.secure = false
|
13
|
+
@cookie.secure.should be_false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "CGI::Cookie#secure= when passed true" do
|
18
|
+
before(:each) do
|
19
|
+
@cookie = CGI::Cookie.new("test-cookie")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns true" do
|
23
|
+
(@cookie.secure = true).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets self to a secure cookie" do
|
27
|
+
@cookie.secure = true
|
28
|
+
@cookie.secure.should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "CGI::Cookie#secure= when passed false" do
|
33
|
+
before(:each) do
|
34
|
+
@cookie = CGI::Cookie.new("test-cookie")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false" do
|
38
|
+
(@cookie.secure = false).should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets self to a non-secure cookie" do
|
42
|
+
@cookie.secure = false
|
43
|
+
@cookie.secure.should be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "CGI::Cookie#secure= when passed Object" do
|
48
|
+
before(:each) do
|
49
|
+
@cookie = CGI::Cookie.new("test-cookie")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not change self's secure value" do
|
53
|
+
@cookie.secure = false
|
54
|
+
|
55
|
+
@cookie.secure = Object.new
|
56
|
+
@cookie.secure.should be_false
|
57
|
+
|
58
|
+
@cookie.secure = "Test"
|
59
|
+
@cookie.secure.should be_false
|
60
|
+
|
61
|
+
@cookie.secure = true
|
62
|
+
|
63
|
+
@cookie.secure = Object.new
|
64
|
+
@cookie.secure.should be_true
|
65
|
+
|
66
|
+
@cookie.secure = "Test"
|
67
|
+
@cookie.secure.should be_true
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#to_s" do
|
4
|
+
it "returns a String representation of self" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.to_s.should == "test-cookie=; path="
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("test-cookie", "value")
|
9
|
+
cookie.to_s.should == "test-cookie=value; path="
|
10
|
+
|
11
|
+
cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
|
12
|
+
cookie.to_s.should == "test-cookie=one&two&three; path="
|
13
|
+
|
14
|
+
cookie = CGI::Cookie.new(
|
15
|
+
'name' => 'test-cookie',
|
16
|
+
'value' => ["one", "two", "three"],
|
17
|
+
'path' => 'some/path/',
|
18
|
+
'domain' => 'example.com',
|
19
|
+
'expires' => Time.at(1196524602),
|
20
|
+
'secure' => true)
|
21
|
+
cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "escapes the self's values" do
|
25
|
+
cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~")
|
26
|
+
cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E; path="
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
describe "CGI::Cookie#value" do
|
4
|
+
it "returns self's value" do
|
5
|
+
cookie = CGI::Cookie.new("test-cookie")
|
6
|
+
cookie.value.should == []
|
7
|
+
|
8
|
+
cookie = CGI::Cookie.new("test-cookie", "one")
|
9
|
+
cookie.value.should == ["one"]
|
10
|
+
|
11
|
+
cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
|
12
|
+
cookie.value.should == ["one", "two", "three"]
|
13
|
+
|
14
|
+
cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"])
|
15
|
+
cookie.value.should == ["one", "two", "three"]
|
16
|
+
end
|
17
|
+
|
18
|
+
ruby_bug "http://redmine.ruby-lang.org/issues/show/229", "1.8.7" do
|
19
|
+
it "is in synch with self" do
|
20
|
+
fail = []
|
21
|
+
[
|
22
|
+
:pop,
|
23
|
+
:shift,
|
24
|
+
[:<<, "Hello"],
|
25
|
+
[:push, "Hello"],
|
26
|
+
[:unshift, "World"],
|
27
|
+
[:replace, ["A", "B"]],
|
28
|
+
[:[]=, 1, "Set"],
|
29
|
+
[:delete, "first"],
|
30
|
+
[:delete_at, 0],
|
31
|
+
].each do |method, *args|
|
32
|
+
cookie1 = CGI::Cookie.new("test-cookie", "first", "second")
|
33
|
+
cookie2 = CGI::Cookie.new("test-cookie", "first", "second")
|
34
|
+
cookie1.send(method, *args)
|
35
|
+
cookie2.value.send(method, *args)
|
36
|
+
fail << method unless cookie1.value == cookie2.value
|
37
|
+
end
|
38
|
+
fail.should be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "CGI::Cookie#value=" do
|
44
|
+
before(:each) do
|
45
|
+
@cookie = CGI::Cookie.new("test-cookie")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "sets self's value" do
|
49
|
+
@cookie.value = ["one"]
|
50
|
+
@cookie.value.should == ["one"]
|
51
|
+
|
52
|
+
@cookie.value = ["one", "two", "three"]
|
53
|
+
@cookie.value.should == ["one", "two", "three"]
|
54
|
+
end
|
55
|
+
|
56
|
+
ruby_bug "http://redmine.ruby-lang.org/issues/show/229", "1.8.7" do
|
57
|
+
it "automatically converts the passed Object to an Array using #Array" do
|
58
|
+
@cookie.value = "test"
|
59
|
+
@cookie.value.should == ["test"]
|
60
|
+
|
61
|
+
obj = mock("to_a")
|
62
|
+
obj.should_receive(:to_a).and_return(["1", "2"])
|
63
|
+
@cookie.value = obj
|
64
|
+
@cookie.value.should == ["1", "2"]
|
65
|
+
|
66
|
+
obj = mock("to_ary")
|
67
|
+
obj.should_receive(:to_ary).and_return(["1", "2"])
|
68
|
+
@cookie.value = obj
|
69
|
+
@cookie.value.should == ["1", "2"]
|
70
|
+
end
|
71
|
+
|
72
|
+
it "does keep self and the values in sync" do
|
73
|
+
@cookie.value = ["one", "two", "three"]
|
74
|
+
@cookie[0].should == "one"
|
75
|
+
@cookie[1].should == "two"
|
76
|
+
@cookie[2].should == "three"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|