diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index b0c6a97..595c7d6 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -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}" diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index cbe8a11..94d412d 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -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