mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Booleanize the value if the key name is suffixed with a "?".
Neglect the "!" suffix that is not suitable for an attribute name while at it.
This commit is contained in:
parent
ad42622d3b
commit
0cf86222f6
2 changed files with 10 additions and 1 deletions
|
|
@ -56,7 +56,9 @@ class HTTP::Cookie
|
||||||
for_domain = false
|
for_domain = false
|
||||||
attr_hash.each_pair { |key, val|
|
attr_hash.each_pair { |key, val|
|
||||||
skey = key.to_s.downcase
|
skey = key.to_s.downcase
|
||||||
skey.sub!(/[!?]\z/, '')
|
if skey.sub!(/\?\z/, '')
|
||||||
|
val = val ? true : false
|
||||||
|
end
|
||||||
case skey
|
case skey
|
||||||
when 'for_domain'
|
when 'for_domain'
|
||||||
for_domain = !!val
|
for_domain = !!val
|
||||||
|
|
|
||||||
|
|
@ -455,6 +455,13 @@ 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
|
||||||
|
|
||||||
|
cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.org', :for_domain? => true)
|
||||||
|
assert_equal 'key', cookie.name
|
||||||
|
assert_equal 'value', cookie.value
|
||||||
|
assert_equal expires, cookie.expires
|
||||||
|
assert_equal 'example.org', cookie.domain
|
||||||
|
assert_equal true, cookie.for_domain?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_domain=
|
def test_domain=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue