mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
HTTP::CookieJar#add: Check if both the domain and path of the cookie are set.
This commit is contained in:
parent
82deac2f19
commit
1731b155e6
2 changed files with 15 additions and 2 deletions
|
|
@ -9,8 +9,6 @@ end
|
|||
class HTTP::CookieJar
|
||||
include Enumerable
|
||||
|
||||
# add_cookie wants something resembling a URI.
|
||||
|
||||
attr_reader :jar
|
||||
|
||||
def initialize
|
||||
|
|
@ -23,6 +21,9 @@ class HTTP::CookieJar
|
|||
|
||||
# Add a +cookie+ to the jar and return self.
|
||||
def add(cookie)
|
||||
if cookie.domain.nil? || cookie.path.nil?
|
||||
raise ArgumentError, "a cookie with unknown domain or path cannot be added"
|
||||
end
|
||||
normal_domain = cookie.domain_name.hostname
|
||||
|
||||
((@jar[normal_domain] ||= {})[cookie.path] ||= {})[cookie.name] = cookie
|
||||
|
|
|
|||
|
|
@ -171,6 +171,18 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|||
assert_equal(1, @jar.cookies(url).length)
|
||||
end
|
||||
|
||||
def test_add_rejects_cookies_with_unknown_domain_or_path
|
||||
cookie = HTTP::Cookie.new(cookie_values.reject { |k,v| [:origin, :domain].include?(k) })
|
||||
assert_raises(ArgumentError) {
|
||||
@jar.add(cookie)
|
||||
}
|
||||
|
||||
cookie = HTTP::Cookie.new(cookie_values.reject { |k,v| [:origin, :path].include?(k) })
|
||||
assert_raises(ArgumentError) {
|
||||
@jar.add(cookie)
|
||||
}
|
||||
end
|
||||
|
||||
def test_add_does_not_reject_cookies_from_a_nested_subdomain
|
||||
url = URI 'http://y.x.foo.com'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue