Disallow changing the origin of a cookie once it is set.

This commit is contained in:
Akinori MUSHA 2012-10-17 22:28:57 +09:00
parent 532101a102
commit 1a471513de
2 changed files with 5 additions and 0 deletions

View file

@ -220,6 +220,8 @@ class HTTP::Cookie
end
def origin=(origin)
@origin.nil? or
raise ArgumentError, "origin cannot be changed once it is set"
origin = URI(origin)
acceptable_from_uri?(origin) or
raise ArgumentError, "unacceptable cookie sent from URI #{origin}"

View file

@ -505,6 +505,9 @@ class TestHTTPCookie < Test::Unit::TestCase
assert_equal '/', cookie.path
assert_equal 'example.com', cookie.domain
assert_equal true, cookie.for_domain
assert_raises(ArgumentError) {
cookie.origin = URI.parse('http://www.example.com/')
}
cookie_str = 'a=b; domain=example.com'
cookie = HTTP::Cookie.parse(cookie_str).first