From 8b78e3d1e436f8897a7724367c44b983d48c0e81 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 26 Mar 2013 02:09:35 +0900 Subject: [PATCH] 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. --- lib/http/cookie_jar/cookiestxt_saver.rb | 2 +- test/test_http_cookie_jar.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/http/cookie_jar/cookiestxt_saver.rb b/lib/http/cookie_jar/cookiestxt_saver.rb index 09df0bd..a19a841 100644 --- a/lib/http/cookie_jar/cookiestxt_saver.rb +++ b/lib/http/cookie_jar/cookiestxt_saver.rb @@ -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, diff --git a/test/test_http_cookie_jar.rb b/test/test_http_cookie_jar.rb index 4330134..c104e41 100644 --- a/test/test_http_cookie_jar.rb +++ b/test/test_http_cookie_jar.rb @@ -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|