http-cookie 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/http/cookie.rb CHANGED
@@ -342,6 +342,7 @@ class HTTP::Cookie
342
342
 
343
343
  def acceptable_from_uri?(uri)
344
344
  uri = URI(uri)
345
+ return false unless URI::HTTP === uri && uri.host
345
346
  host = DomainName.new(uri.host)
346
347
 
347
348
  # RFC 6265 5.3
@@ -359,11 +360,11 @@ class HTTP::Cookie
359
360
  end
360
361
 
361
362
  def valid_for_uri?(uri)
362
- uri = URI(uri)
363
363
  if @domain.nil?
364
364
  raise "cannot tell if this cookie is valid because the domain is unknown"
365
365
  end
366
- return false if secure? && uri.scheme != 'https'
366
+ uri = URI(uri)
367
+ return false if secure? && !(URI::HTTPS === uri)
367
368
  acceptable_from_uri?(uri) && HTTP::Cookie.normalize_path(uri.path).start_with?(@path)
368
369
  end
369
370
 
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  class Cookie
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -67,21 +67,19 @@ class HTTP::CookieJar
67
67
 
68
68
  # Iterates over all cookies that are not expired.
69
69
  #
70
- # Available option keywords are below:
71
- #
72
- # * +uri+
73
- #
74
- # Specify a URI/URL indicating the destination of the cookies
75
- # being selected. Every cookie yielded should be good to send to
76
- # the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
77
- # true.
70
+ # An optional argument +uri+ specifies a URI/URL indicating the
71
+ # destination of the cookies being selected. Every cookie yielded
72
+ # should be good to send to the given URI,
73
+ # i.e. cookie.valid_for_uri?(uri) evaluates to true.
78
74
  #
79
- # If (and only if) this option is given, last access time of each
80
- # cookie is updated to the current time.
75
+ # If (and only if) the +uri+ option is given, last access time of
76
+ # each cookie is updated to the current time.
81
77
  def each(uri = nil, &block)
82
78
  block_given? or return enum_for(__method__, uri)
83
79
 
84
80
  if uri
81
+ uri = URI(uri)
82
+ return self unless URI::HTTP === uri && uri.host
85
83
  block = proc { |cookie|
86
84
  yield cookie if cookie.valid_for_uri?(uri)
87
85
  }
@@ -54,23 +54,23 @@ class HTTP::CookieJar::AbstractStore
54
54
 
55
55
  # Iterates over all cookies that are not expired.
56
56
  #
57
- # Available option keywords are below:
57
+ # An optional argument +uri+ specifies a URI object indicating the
58
+ # destination of the cookies being selected. Every cookie yielded
59
+ # should be good to send to the given URI,
60
+ # i.e. cookie.valid_for_uri?(uri) evaluates to true.
58
61
  #
59
- # * +uri+
60
- #
61
- # Specify a URI object indicating the destination of the cookies
62
- # being selected. Every cookie yielded should be good to send to
63
- # the given URI, i.e. cookie.valid_for_uri?(uri) evaluates to
64
- # true.
65
- #
66
- # If (and only if) this option is given, last access time of each
67
- # cookie is updated to the current time.
68
- def each(options = nil, &block)
62
+ # If (and only if) the +uri+ option is given, last access time of
63
+ # each cookie is updated to the current time.
64
+ def each(uri = nil, &block)
69
65
  raise
70
66
  self
71
67
  end
72
68
  include Enumerable
73
69
 
70
+ def empty?
71
+ raise
72
+ end
73
+
74
74
  def clear
75
75
  raise
76
76
  self
@@ -51,7 +51,6 @@ class HTTP::CookieJar
51
51
 
52
52
  def each(uri = nil)
53
53
  if uri
54
- uri = URI(uri)
55
54
  thost = DomainName.new(uri.host)
56
55
  tpath = HTTP::Cookie.normalize_path(uri.path)
57
56
  @jar.each { |domain, paths|
@@ -83,6 +82,7 @@ class HTTP::CookieJar
83
82
  }
84
83
  }
85
84
  end
85
+ self
86
86
  end
87
87
 
88
88
  def clear
@@ -576,6 +576,7 @@ class TestHTTPCookie < Test::Unit::TestCase
576
576
  assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
577
577
  assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
578
578
  assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
579
+ assert_equal false, cookie.valid_for_uri?(URI('file:///dir/test.html'))
579
580
 
580
581
  cookie = HTTP::Cookie.parse('a=b; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first
581
582
  assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
@@ -586,6 +587,7 @@ class TestHTTPCookie < Test::Unit::TestCase
586
587
  assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
587
588
  assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
588
589
  assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
590
+ assert_equal false, cookie.valid_for_uri?(URI('file:///dir/test.html'))
589
591
 
590
592
  cookie = HTTP::Cookie.parse('a=b; domain=example.com; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first
591
593
  assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
@@ -596,15 +598,18 @@ class TestHTTPCookie < Test::Unit::TestCase
596
598
  assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
597
599
  assert_equal true, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
598
600
  assert_equal true, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
601
+ assert_equal false, cookie.valid_for_uri?(URI('file:///dir2/test.html'))
599
602
 
600
603
  cookie = HTTP::Cookie.parse('a=b; secure', :origin => URI('https://example.com/dir/file.html')).first
601
604
  assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
602
605
  assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
603
606
  assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
604
607
  assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
608
+ assert_equal false, cookie.valid_for_uri?(URI('file:///dir2/test.html'))
605
609
 
606
610
  cookie = HTTP::Cookie.parse('a=b', :origin => URI('https://example.com/')).first
607
611
  assert_equal true, cookie.valid_for_uri?(URI('https://example.com'))
612
+ assert_equal false, cookie.valid_for_uri?(URI('file:///'))
608
613
  end
609
614
 
610
615
  def test_migration
@@ -270,6 +270,16 @@ class TestHTTPCookieJar < Test::Unit::TestCase
270
270
  assert_equal(0, @jar.cookies(url).length)
271
271
  end
272
272
 
273
+ def test_cookies_no_host
274
+ url = URI 'file:///path/'
275
+
276
+ assert_raises(ArgumentError) {
277
+ @jar.add(HTTP::Cookie.new(cookie_values(:origin => url)))
278
+ }
279
+
280
+ assert_equal(0, @jar.cookies(url).length)
281
+ end
282
+
273
283
  def test_clear
274
284
  url = URI 'http://rubyforge.org/'
275
285
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-cookie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: