diff --git a/lib/http/cookie.rb b/lib/http/cookie.rb index 6f56acd..bdd84db 100644 --- a/lib/http/cookie.rb +++ b/lib/http/cookie.rb @@ -564,9 +564,9 @@ class HTTP::Cookie def acceptable? case when @domain.nil? - raise ArgumentError, "domain is missing" + raise "domain is missing" when @path.nil? - raise ArgumentError, "path is missing" + raise "path is missing" when @origin.nil? true else @@ -574,8 +574,8 @@ class HTTP::Cookie end end - # Tests if it is OK to send this cookie to a given `uri`. A runtime - # error is raised if the cookie's domain is unknown. + # Tests if it is OK to send this cookie to a given `uri`. A + # RuntimeError is raised if the cookie's domain is unknown. def valid_for_uri?(uri) if @domain.nil? raise "cannot tell if this cookie is valid because the domain is unknown" diff --git a/lib/http/cookie_jar.rb b/lib/http/cookie_jar.rb index ce3e7eb..f1ba2d1 100644 --- a/lib/http/cookie_jar.rb +++ b/lib/http/cookie_jar.rb @@ -69,7 +69,12 @@ class HTTP::CookieJar # jar.origin = origin # jar.add(cookie) # acceptance check is performed def add(cookie) - @store.add(cookie) if cookie.acceptable? + @store.add(cookie) if + begin + cookie.acceptable? + rescue RuntimeError => e + raise ArgumentError, e.message + end self end alias << add diff --git a/test/test_http_cookie.rb b/test/test_http_cookie.rb index 160db16..6226fcd 100644 --- a/test/test_http_cookie.rb +++ b/test/test_http_cookie.rb @@ -523,7 +523,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 'key', cookie.name assert_equal 'value', cookie.value assert_equal nil, cookie.expires - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { cookie.acceptable? } @@ -534,7 +534,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 'key', cookie.name assert_equal 'value', cookie.value assert_equal expires, cookie.expires - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { cookie.acceptable? } @@ -543,7 +543,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 'value', cookie.value assert_equal expires, cookie.expires assert_equal false, cookie.for_domain? - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { # domain and path are missing cookie.acceptable? } @@ -553,7 +553,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 'value', cookie.value assert_equal expires, cookie.expires assert_equal true, cookie.for_domain? - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { # path is missing cookie.acceptable? } @@ -563,7 +563,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal 'value', cookie.value assert_equal expires, cookie.expires assert_equal false, cookie.for_domain? - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { # path is missing cookie.acceptable? } @@ -574,7 +574,7 @@ class TestHTTPCookie < Test::Unit::TestCase assert_equal expires, cookie.expires assert_equal 'example.org', cookie.domain assert_equal true, cookie.for_domain? - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { # path is missing cookie.acceptable? } @@ -849,7 +849,7 @@ class TestHTTPCookie < Test::Unit::TestCase cookie.domain = d assert_equal nil, cookie.domain, "domain=#{d.inspect}" assert_equal nil, cookie.domain_name, "domain=#{d.inspect}" - assert_raises(ArgumentError) { + assert_raises(RuntimeError) { cookie.acceptable? }