mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +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)"
|
raise ArgumentError, "wrong number of arguments (#{args.size} for 1-3)"
|
||||||
end
|
end
|
||||||
for_domain = false
|
for_domain = false
|
||||||
max_age = origin = nil
|
domain = max_age = origin = nil
|
||||||
attr_hash.each_pair { |key, val|
|
attr_hash.each_pair { |key, val|
|
||||||
skey = key.to_s.downcase
|
skey = key.to_s.downcase
|
||||||
if skey.sub!(/\?\z/, '')
|
if skey.sub!(/\?\z/, '')
|
||||||
|
|
@ -179,6 +179,8 @@ class HTTP::Cookie
|
||||||
case skey
|
case skey
|
||||||
when 'for_domain'
|
when 'for_domain'
|
||||||
for_domain = !!val
|
for_domain = !!val
|
||||||
|
when 'domain'
|
||||||
|
domain = val
|
||||||
when 'origin'
|
when 'origin'
|
||||||
origin = val
|
origin = val
|
||||||
when 'max_age'
|
when 'max_age'
|
||||||
|
|
@ -193,6 +195,7 @@ class HTTP::Cookie
|
||||||
raise ArgumentError, "at least name and value must be specified"
|
raise ArgumentError, "at least name and value must be specified"
|
||||||
end
|
end
|
||||||
@for_domain = for_domain
|
@for_domain = for_domain
|
||||||
|
self.domain = domain if domain
|
||||||
self.origin = origin if origin
|
self.origin = origin if origin
|
||||||
self.max_age = max_age if max_age
|
self.max_age = max_age if max_age
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -455,6 +455,19 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
assert_equal 'key', cookie.name
|
assert_equal 'key', cookie.name
|
||||||
assert_equal 'value', cookie.value
|
assert_equal 'value', cookie.value
|
||||||
assert_equal expires, cookie.expires
|
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)
|
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.org', :for_domain? => true)
|
||||||
assert_equal 'key', cookie.name
|
assert_equal 'key', cookie.name
|
||||||
|
|
@ -685,9 +698,8 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
:domain => 'uk',
|
:domain => 'uk',
|
||||||
:for_domain => true,
|
:for_domain => true,
|
||||||
:origin => nil))
|
: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.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/')
|
assert_equal false, cookie.acceptable_from_uri?('http://foo.uk/')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue