From 8be03978a0617c73f51119c393dcb0f889e6528c Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Fri, 15 Mar 2013 11:33:54 +0900 Subject: [PATCH] Make each(uri) not fail if a non-HTTP URL is given. Fix documents with #each. The uri argument was not made a keyword argument. Guarantee that the +uri+ given to AbstractStore#each() is a URI object. Make HashStore#each return self as required. --- lib/http/cookie_jar.rb | 18 ++++++++---------- lib/http/cookie_jar/abstract_store.rb | 18 +++++++----------- lib/http/cookie_jar/hash_store.rb | 2 +- test/test_http_cookie_jar.rb | 2 ++ 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/http/cookie_jar.rb b/lib/http/cookie_jar.rb index fd0ceaa..7e8b04d 100644 --- a/lib/http/cookie_jar.rb +++ b/lib/http/cookie_jar.rb @@ -67,21 +67,19 @@ class HTTP::CookieJar # Iterates over all cookies that are not expired. # - # Available option keywords are below: + # An optional argument +uri+ specifies a URI/URL indicating the + # destination of the cookies being selected. Every cookie yielded + # should be good to send to the given URI, + # i.e. cookie.valid_for_uri?(uri) evaluates to true. # - # * +uri+ - # - # Specify a URI/URL indicating the destination of the cookies - # being selected. Every cookie yielded should be good to send to - # the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to - # true. - # - # If (and only if) this option is given, last access time of each - # cookie is updated to the current time. + # If (and only if) the +uri+ option is given, last access time of + # each cookie is updated to the current time. def each(uri = nil, &block) block_given? or return enum_for(__method__, uri) if uri + uri = URI(uri) + return self unless URI::HTTP === uri && uri.host block = proc { |cookie| yield cookie if cookie.valid_for_uri?(uri) } diff --git a/lib/http/cookie_jar/abstract_store.rb b/lib/http/cookie_jar/abstract_store.rb index 6565ab4..fa854f8 100644 --- a/lib/http/cookie_jar/abstract_store.rb +++ b/lib/http/cookie_jar/abstract_store.rb @@ -54,18 +54,14 @@ class HTTP::CookieJar::AbstractStore # Iterates over all cookies that are not expired. # - # Available option keywords are below: + # An optional argument +uri+ specifies a URI object indicating the + # destination of the cookies being selected. Every cookie yielded + # should be good to send to the given URI, + # i.e. cookie.valid_for_uri?(uri) evaluates to true. # - # * +uri+ - # - # Specify a URI object indicating the destination of the cookies - # being selected. Every cookie yielded should be good to send to - # the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to - # true. - # - # If (and only if) this option is given, last access time of each - # cookie is updated to the current time. - def each(options = nil, &block) + # If (and only if) the +uri+ option is given, last access time of + # each cookie is updated to the current time. + def each(uri = nil, &block) raise self end diff --git a/lib/http/cookie_jar/hash_store.rb b/lib/http/cookie_jar/hash_store.rb index e63c19a..76a35da 100644 --- a/lib/http/cookie_jar/hash_store.rb +++ b/lib/http/cookie_jar/hash_store.rb @@ -51,7 +51,6 @@ class HTTP::CookieJar def each(uri = nil) if uri - uri = URI(uri) thost = DomainName.new(uri.host) tpath = HTTP::Cookie.normalize_path(uri.path) @jar.each { |domain, paths| @@ -83,6 +82,7 @@ class HTTP::CookieJar } } end + self end def clear diff --git a/test/test_http_cookie_jar.rb b/test/test_http_cookie_jar.rb index 250072d..30364ea 100644 --- a/test/test_http_cookie_jar.rb +++ b/test/test_http_cookie_jar.rb @@ -276,6 +276,8 @@ class TestHTTPCookieJar < Test::Unit::TestCase assert_raises(ArgumentError) { @jar.add(HTTP::Cookie.new(cookie_values(:origin => url))) } + + assert_equal(0, @jar.cookies(url).length) end def test_clear