Merge pull request #10 from marxarelli/fix/host-only-cookie-domain-comparison

Fix host-only cookies for unqualified hostnames
This commit is contained in:
Akinori MUSHA 2016-12-09 21:48:59 +09:00 committed by GitHub
commit 24b5d407d9
2 changed files with 11 additions and 2 deletions

View file

@ -67,10 +67,8 @@ class HTTP::CookieJar
def each(uri = nil) # :yield: cookie
now = Time.now
if uri
thost = DomainName.new(uri.host)
tpath = uri.path
@jar.each { |domain, paths|
next unless thost.cookie_domain?(domain)
paths.each { |path, hash|
next unless HTTP::Cookie.path_match?(path, tpath)
hash.delete_if { |name, cookie|

View file

@ -139,6 +139,17 @@ module TestHTTPCookieJar
assert_equal(0, @jar.cookies(URI('http://www.rubyforge.org/')).length)
end
def test_host_only_with_unqualified_hostname
@jar.add(HTTP::Cookie.new(cookie_values(
:origin => 'http://localhost/', :domain => 'localhost', :for_domain => false)))
assert_equal(1, @jar.cookies(URI('http://localhost/')).length)
assert_equal(1, @jar.cookies(URI('http://Localhost/')).length)
assert_equal(1, @jar.cookies(URI('https://Localhost/')).length)
end
def test_empty_value
url = URI 'http://rubyforge.org/'
values = cookie_values(:value => "")