cookiejar 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cookiejar/cookie_validation.rb +4 -4
- data/lib/cookiejar/jar.rb +13 -5
- data/test/cookie_validation_test.rb +4 -0
- data/test/jar_test.rb +21 -0
- metadata +15 -5
@@ -39,7 +39,7 @@ module CookieJar
|
|
39
39
|
end
|
40
40
|
BASE_HOSTNAME = /#{PATTERN::BASE_HOSTNAME}/
|
41
41
|
BASE_PATH = /\A((?:[^\/?#]*\/)*)/
|
42
|
-
IPADDR = /\A#{PATTERN::
|
42
|
+
IPADDR = /\A#{PATTERN::IPV4ADDR}\Z|\A#{PATTERN::IPV6ADDR}\Z/
|
43
43
|
HDN = /\A#{PATTERN::HOSTNAME}\Z/
|
44
44
|
TOKEN = /\A#{PATTERN::TOKEN}\Z/
|
45
45
|
PARAM1 = /\A(#{PATTERN::TOKEN})(?:=#{PATTERN::VALUE1})?\Z/
|
@@ -355,11 +355,11 @@ module CookieJar
|
|
355
355
|
first = true
|
356
356
|
index = 0
|
357
357
|
begin
|
358
|
-
md = PARAM2.match set_cookie_value
|
359
|
-
if md.nil? || md.offset(0).first !=
|
358
|
+
md = PARAM2.match set_cookie_value[index..-1]
|
359
|
+
if md.nil? || md.offset(0).first != 0
|
360
360
|
raise InvalidCookieError.new "Invalid Set-Cookie2 header '#{set_cookie_value}'"
|
361
361
|
end
|
362
|
-
index
|
362
|
+
index+=md.offset(0)[1]
|
363
363
|
|
364
364
|
key = md[1].downcase.to_sym
|
365
365
|
keyvalue = md[2] || md[3]
|
data/lib/cookiejar/jar.rb
CHANGED
@@ -86,12 +86,20 @@ module CookieJar
|
|
86
86
|
# @raise [InvalidCookieError] if one of the cookie headers contained
|
87
87
|
# invalid formatting or data
|
88
88
|
def set_cookies_from_headers request_uri, http_headers
|
89
|
-
|
90
|
-
|
89
|
+
set_cookie_key = http_headers.keys.detect { |k| /\ASet-Cookie\Z/i.match k }
|
90
|
+
cookies = gather_header_values http_headers[set_cookie_key] do |value|
|
91
|
+
begin
|
92
|
+
Cookie.from_set_cookie request_uri, value
|
93
|
+
rescue InvalidCookieError
|
94
|
+
end
|
91
95
|
end
|
92
96
|
|
93
|
-
|
94
|
-
|
97
|
+
set_cookie2_key = http_headers.keys.detect { |k| /\ASet-Cookie2\Z/i.match k }
|
98
|
+
cookies += gather_header_values(http_headers[set_cookie2_key]) do |value|
|
99
|
+
begin
|
100
|
+
Cookie.from_set_cookie2 request_uri, value
|
101
|
+
rescue InvalidCookieError
|
102
|
+
end
|
95
103
|
end
|
96
104
|
|
97
105
|
# build the list of cookies, using a Jar. Since Set-Cookie2 values
|
@@ -277,7 +285,7 @@ module CookieJar
|
|
277
285
|
elsif http_header_value.is_a? String
|
278
286
|
result << block.call(http_header_value)
|
279
287
|
end
|
280
|
-
result
|
288
|
+
result.compact
|
281
289
|
end
|
282
290
|
|
283
291
|
def to_uri request_uri
|
@@ -125,6 +125,10 @@ describe CookieValidation do
|
|
125
125
|
CookieValidation.compute_search_domains('http://foo.com/').should ==
|
126
126
|
['foo.com', '.foo.com']
|
127
127
|
end
|
128
|
+
it "should handle hexadecimal TLDs" do
|
129
|
+
CookieValidation.compute_search_domains('http://tiny.cc/').should ==
|
130
|
+
['tiny.cc', '.tiny.cc']
|
131
|
+
end
|
128
132
|
it "should handle IP addresses" do
|
129
133
|
CookieValidation.compute_search_domains('http://127.0.0.1/').should ==
|
130
134
|
['127.0.0.1']
|
data/test/jar_test.rb
CHANGED
@@ -121,6 +121,13 @@ describe Jar do
|
|
121
121
|
cookies.should have(1).items
|
122
122
|
jar.to_a.should have(1).items
|
123
123
|
end
|
124
|
+
it "should handle a set-cookie header" do
|
125
|
+
jar = Jar.new
|
126
|
+
cookies = jar.set_cookies_from_headers 'http://localhost/',
|
127
|
+
{ 'set-cookie' => 'foo=bar' }
|
128
|
+
cookies.should have(1).items
|
129
|
+
jar.to_a.should have(1).items
|
130
|
+
end
|
124
131
|
it "should handle multiple Set-Cookie headers" do
|
125
132
|
jar = Jar.new
|
126
133
|
cookies = jar.set_cookies_from_headers 'http://localhost/',
|
@@ -135,6 +142,13 @@ describe Jar do
|
|
135
142
|
cookies.should have(1).items
|
136
143
|
jar.to_a.should have(1).items
|
137
144
|
end
|
145
|
+
it "should handle a set-cookie2 header" do
|
146
|
+
jar = Jar.new
|
147
|
+
cookies = jar.set_cookies_from_headers 'http://localhost/',
|
148
|
+
{ 'set-cookie2' => 'foo=bar;Version=1' }
|
149
|
+
cookies.should have(1).items
|
150
|
+
jar.to_a.should have(1).items
|
151
|
+
end
|
138
152
|
it "should handle multiple Set-Cookie2 headers" do
|
139
153
|
jar = Jar.new
|
140
154
|
cookies = jar.set_cookies_from_headers 'http://localhost/',
|
@@ -162,6 +176,13 @@ describe Jar do
|
|
162
176
|
cookie.name == 'foo'
|
163
177
|
end.version.should == 1
|
164
178
|
end
|
179
|
+
it "should silently drop invalid cookies" do
|
180
|
+
jar = Jar.new
|
181
|
+
cookies = jar.set_cookies_from_headers 'http://localhost/',
|
182
|
+
{ 'Set-Cookie' => ['foo=bar','bar=baz;domain=.foo.com'] }
|
183
|
+
cookies.should have(1).items
|
184
|
+
jar.to_a.should have(1).items
|
185
|
+
end
|
165
186
|
end
|
166
187
|
begin
|
167
188
|
require 'json'
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cookiejar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- David Waite
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-06-14 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -40,21 +45,26 @@ rdoc_options:
|
|
40
45
|
require_paths:
|
41
46
|
- lib
|
42
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
43
49
|
requirements:
|
44
50
|
- - ">="
|
45
51
|
- !ruby/object:Gem::Version
|
52
|
+
hash: -1050474939376950864
|
53
|
+
segments:
|
54
|
+
- 0
|
46
55
|
version: "0"
|
47
|
-
version:
|
48
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
49
58
|
requirements:
|
50
59
|
- - ">="
|
51
60
|
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
52
63
|
version: "0"
|
53
|
-
version:
|
54
64
|
requirements: []
|
55
65
|
|
56
66
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.7
|
58
68
|
signing_key:
|
59
69
|
specification_version: 3
|
60
70
|
summary: Client-side HTTP Cookie library
|