Skip to content

Commit

Permalink
Send cookie for '.example.com' on requests for 'example.com' (Issue s…
Browse files Browse the repository at this point in the history
  • Loading branch information
runpaint committed Aug 5, 2011
1 parent eb9e8dc commit 9cef3e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mechanize/cookie_jar.rb
Expand Up @@ -40,7 +40,7 @@ def cookies(url)
domains = @jar.find_all { |domain, _|
cookie_domain = self.class.strip_port(domain)
if cookie_domain.start_with?('.')
url.host =~ /#{Regexp.escape cookie_domain}$/i
url.host =~ /(^|\.)#{Regexp.escape cookie_domain[1..-1]}$/i
else
url.host =~ /^#{Regexp.escape cookie_domain}$/i
end
Expand Down
16 changes: 16 additions & 0 deletions test/test_mechanize_cookie_jar.rb
Expand Up @@ -184,6 +184,22 @@ def test_cookies_with_leading_dot_match_subdomains
assert_equal(1, @jar.cookies(url).length)
end

def test_cookies_with_leading_dot_match_parent_domains
url = URI.parse('http://rubyforge.org/')

@jar.add(url, cookie_from_hash(cookie_values(:domain => '.rubyforge.org')))

assert_equal(1, @jar.cookies(url).length)
end

def test_cookies_with_leading_dot_match_parent_domains_exactly
url = URI.parse('http://arubyforge.org/')

@jar.add(url, cookie_from_hash(cookie_values(:domain => '.rubyforge.org')))

assert_equal(0, @jar.cookies(url).length)
end

def test_cookies_dot
url = URI.parse('http://www.host.example/')

Expand Down

0 comments on commit 9cef3e8

Please sign in to comment.