CookiestxtSaver: Prefix the domain field with a dot if the domain flag is on.

The leading dot itself should be meaningless since there is the second
field to tell if the cookie is issued for a domain and that was the
reason I once removed it, but on second thought it doesn't hurt to put
one.
This commit is contained in:
Akinori MUSHA 2013-03-26 02:09:35 +09:00
parent f2ea366de2
commit 8b78e3d1e4
2 changed files with 9 additions and 3 deletions

View file

@ -32,7 +32,7 @@ class HTTP::CookieJar::CookiestxtSaver < HTTP::CookieJar::AbstractSaver
def cookie_to_record(cookie)
cookie.instance_eval {
[
@domain,
dot_domain,
@for_domain ? True : False,
@path,
@secure ? True : False,

View file

@ -368,10 +368,16 @@ class TestHTTPCookieJar < Test::Unit::TestCase
assert_equal(3, @jar.cookies(url).length)
Dir.mktmpdir do |dir|
@jar.save(File.join(dir, "cookies.txt"), :cookiestxt)
filename = File.join(dir, "cookies.txt")
@jar.save(filename, :cookiestxt)
content = File.read(filename)
assert_match(/^\.rubyforge\.org\t.*\tFoo\t/, content)
assert_match(/^rubyforge\.org\t.*\tBaz\t/, content)
jar = HTTP::CookieJar.new
jar.load(File.join(dir, "cookies.txt"), :cookiestxt) # HACK test the format
jar.load(filename, :cookiestxt) # HACK test the format
cookies = jar.cookies(url)
assert_equal(2, cookies.length)
cookies.each { |cookie|