mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Fix handling of the :for_domain option in HTTP::Cookie.new().
This commit is contained in:
parent
add4a367fd
commit
11a9df8559
2 changed files with 18 additions and 3 deletions
|
|
@ -170,7 +170,7 @@ class HTTP::Cookie
|
|||
raise ArgumentError, "wrong number of arguments (#{args.size} for 1-3)"
|
||||
end
|
||||
for_domain = false
|
||||
max_age = origin = nil
|
||||
domain = max_age = origin = nil
|
||||
attr_hash.each_pair { |key, val|
|
||||
skey = key.to_s.downcase
|
||||
if skey.sub!(/\?\z/, '')
|
||||
|
|
@ -179,6 +179,8 @@ class HTTP::Cookie
|
|||
case skey
|
||||
when 'for_domain'
|
||||
for_domain = !!val
|
||||
when 'domain'
|
||||
domain = val
|
||||
when 'origin'
|
||||
origin = val
|
||||
when 'max_age'
|
||||
|
|
@ -193,6 +195,7 @@ class HTTP::Cookie
|
|||
raise ArgumentError, "at least name and value must be specified"
|
||||
end
|
||||
@for_domain = for_domain
|
||||
self.domain = domain if domain
|
||||
self.origin = origin if origin
|
||||
self.max_age = max_age if max_age
|
||||
end
|
||||
|
|
|
|||
|
|
@ -455,6 +455,19 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|||
assert_equal 'key', cookie.name
|
||||
assert_equal 'value', cookie.value
|
||||
assert_equal expires, cookie.expires
|
||||
assert_equal false, cookie.for_domain?
|
||||
|
||||
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => '.example.com')
|
||||
assert_equal 'key', cookie.name
|
||||
assert_equal 'value', cookie.value
|
||||
assert_equal expires, cookie.expires
|
||||
assert_equal true, cookie.for_domain?
|
||||
|
||||
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.com', :for_domain => false)
|
||||
assert_equal 'key', cookie.name
|
||||
assert_equal 'value', cookie.value
|
||||
assert_equal expires, cookie.expires
|
||||
assert_equal false, cookie.for_domain?
|
||||
|
||||
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.org', :for_domain? => true)
|
||||
assert_equal 'key', cookie.name
|
||||
|
|
@ -685,9 +698,8 @@ class TestHTTPCookie < Test::Unit::TestCase
|
|||
:domain => 'uk',
|
||||
:for_domain => true,
|
||||
:origin => nil))
|
||||
assert_equal true, cookie.for_domain?
|
||||
assert_equal false, cookie.for_domain?
|
||||
assert_equal true, cookie.acceptable_from_uri?('http://uk/')
|
||||
assert_equal true, cookie.for_domain? # bug: acceptable_from_uri? changed it to false
|
||||
assert_equal false, cookie.acceptable_from_uri?('http://foo.uk/')
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue