Permalink
Browse files

Writing cookies: Prefix wildcard domains with "."

If a cookie matches a wildcard domain, e.g. "(anything).example.com",
then the line written out to a Netscape-formatted cookies.txt file must
begin with a dot, e.g. ".example.com" not "example.com".  This is
redundant with the second field of the line, a TRUE/FALSE value
indicating whether the domain is a wildcard, but that's the way it goes.
  • Loading branch information...
1 parent 7c49ee0 commit dae27334815082e228cfd344e2452a17121f6847 @mmorearty mmorearty committed with Mike Morearty Feb 19, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/mechanize/cookie_jar.rb
@@ -192,7 +192,7 @@ def dump_cookiestxt(io)
"#{Mechanize::VERSION} https://github.com/sparklemotion/mechanize.\n\n"
to_a.each do |cookie|
io.puts([
- cookie.domain,
+ (cookie.for_domain? ? "." : "") + cookie.domain,
cookie.for_domain? ? "TRUE" : "FALSE",
cookie.path,
cookie.secure ? "TRUE" : "FALSE",

0 comments on commit dae2733

Please sign in to comment.