mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Inhibit a domain-less cookie from being used for checking validity.
This commit is contained in:
parent
c3e4fae60c
commit
dd3ca9a0f1
2 changed files with 11 additions and 1 deletions
|
|
@ -265,8 +265,11 @@ class HTTP::Cookie
|
||||||
|
|
||||||
def valid_for_uri?(uri)
|
def valid_for_uri?(uri)
|
||||||
uri = URI(uri)
|
uri = URI(uri)
|
||||||
|
if @domain.nil?
|
||||||
|
raise "cannot tell if this cookie is valid because the domain is unknown"
|
||||||
|
end
|
||||||
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) && uri.path.start_with?(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
||||||
|
|
@ -465,6 +465,13 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
assert_equal true, cookie.for_domain?
|
assert_equal true, cookie.for_domain?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_domain_nil
|
||||||
|
cookie = HTTP::Cookie.parse('a=b').first
|
||||||
|
assert_raises(RuntimeError) {
|
||||||
|
cookie.valid_for_uri?('http://example.com/')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_domain=
|
def test_domain=
|
||||||
url = URI.parse('http://host.dom.example.com:8080/')
|
url = URI.parse('http://host.dom.example.com:8080/')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue