mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Make valid_for_uri? and acceptable_from_uri? accept a URL string also.
This commit is contained in:
parent
e010e8f30e
commit
75f7ee6505
2 changed files with 3 additions and 0 deletions
|
|
@ -246,6 +246,7 @@ class HTTP::Cookie
|
||||||
alias secure? secure
|
alias secure? secure
|
||||||
|
|
||||||
def acceptable_from_uri?(uri)
|
def acceptable_from_uri?(uri)
|
||||||
|
uri = URI(uri)
|
||||||
host = DomainName.new(uri.host)
|
host = DomainName.new(uri.host)
|
||||||
|
|
||||||
# RFC 6265 5.3
|
# RFC 6265 5.3
|
||||||
|
|
@ -263,6 +264,7 @@ class HTTP::Cookie
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_for_uri?(uri)
|
def valid_for_uri?(uri)
|
||||||
|
uri = URI(uri)
|
||||||
return false if secure? && uri.scheme != 'https'
|
return false if secure? && uri.scheme != 'https'
|
||||||
acceptable_from_uri?(uri) && (@path.nil? || uri.path.start_with?(@path))
|
acceptable_from_uri?(uri) && (@path.nil? || uri.path.start_with?(@path))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -519,6 +519,7 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
def test_valid_for_uri?
|
def test_valid_for_uri?
|
||||||
cookie = HTTP::Cookie.parse('a=b', :origin => URI('http://example.com/dir/file.html')).first
|
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?(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 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('https://example.com/dir2/test.html'))
|
||||||
assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
|
assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue