Make valid_for_uri? and acceptable_from_uri? accept a URL string also.

This commit is contained in:
Akinori MUSHA 2012-10-18 18:57:46 +09:00
parent e010e8f30e
commit 75f7ee6505
2 changed files with 3 additions and 0 deletions

View file

@ -246,6 +246,7 @@ class HTTP::Cookie
alias secure? secure
def acceptable_from_uri?(uri)
uri = URI(uri)
host = DomainName.new(uri.host)
# RFC 6265 5.3
@ -263,6 +264,7 @@ class HTTP::Cookie
end
def valid_for_uri?(uri)
uri = URI(uri)
return false if secure? && uri.scheme != 'https'
acceptable_from_uri?(uri) && (@path.nil? || uri.path.start_with?(@path))
end

View file

@ -519,6 +519,7 @@ class TestHTTPCookie < Test::Unit::TestCase
def test_valid_for_uri?
cookie = HTTP::Cookie.parse('a=b', :origin => URI('http://example.com/dir/file.html')).first
assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
assert_equal true, cookie.valid_for_uri?('https://example.com/dir/test.html')
assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))