http-cookie 1.0.5 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5230b0bd44e032652855e7b9e60e3d994ca56adbd57550c7520930d4dbf734a4
4
- data.tar.gz: 65240197f49ac57bac8c6f3d1104cfe4f8fff77e1ac992c05c72d74efbba8300
3
+ metadata.gz: 143890479b8951250d5f45d4528c390e03741d943269abe0901e091b544f95ca
4
+ data.tar.gz: 7bfef9e1bd7cd6cb01f0de248717fade7a1871fb120cd35227657a96c371d384
5
5
  SHA512:
6
- metadata.gz: 7fc5bb2e287d60d060c54eb9fb9ccb6d55c55e84ec35525deff8c088c873d6ac26db86f7f1cf3c03a7cbf05e397b6cd0e3a1e1171c2dcff8848e0345a34b0905
7
- data.tar.gz: 1c85e07a65fac1d5440126bea27dbc01160edc9a791f56e021cd3142070eada54bf1ec3cda31c9d9273f23c3a84c8786c308bcdd27e03f7266c203dde4abdd6f
6
+ metadata.gz: ba03e3c618d888517bc4bb9e95c08cf4c89bbe5a9ec075d31dcaba353d8864b338fe79bf7ad36f45d6e87a114eefabe41ed62a7b62876c3ba55f459e022fb24f
7
+ data.tar.gz: 846fa3243f97982df9b196fbc0645d13cd233105bbaa98e2e42b36f5a95b58c07d7571c213c6b35034b4ea41f1ce415857aabbbfe20042305611608fa3d327df
@@ -0,0 +1 @@
1
+ * @knu
@@ -15,7 +15,7 @@ jobs:
15
15
  matrix:
16
16
  os: [ubuntu]
17
17
  # We still kind of support Ruby 1.8.7
18
- ruby: [2.7, "3.0", 3.1, head, jruby]
18
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "head", "jruby"]
19
19
 
20
20
  name: >-
21
21
  ${{matrix.os}}:ruby-${{matrix.ruby}}
@@ -24,7 +24,7 @@ jobs:
24
24
 
25
25
  steps:
26
26
  - name: Check out
27
- uses: actions/checkout@v2
27
+ uses: actions/checkout@v4
28
28
 
29
29
  - name: Set up ruby and bundle
30
30
  uses: ruby/setup-ruby@v1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 1.0.8 (2024-12-05)
2
+
3
+ - `Cookie#expires=` accepts `DateTime` objects. (#52) @luke-hill @flavorjones
4
+
5
+
6
+ ## 1.0.7 (2024-06-06)
7
+
8
+ - Explicitly require "cgi" to avoid `NameError` in some applications. (#50 by @flavorjones)
9
+
10
+
11
+ ## 1.0.6 (2024-06-01)
12
+
13
+ - Fix error formatting bug in HTTP::CookieJar::AbstractStore (#42 by @andrelaszlo)
14
+ - Allow non-RFC 3986-compliant URLs (#45 by @c960657)
15
+ - Add coverage for Ruby 3.2 and 3.3 (#46 by @flavorjones)
16
+ - Quash ruby 3.4 warnings (#47 by @flavorjones)
17
+
1
18
  ## 1.0.5 (2022-05-25)
2
19
 
3
20
  - Silence SQLite3 warnings
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/http-cookie.svg)](https://badge.fury.io/rb/http-cookie)
2
+
1
3
  # HTTP::Cookie
2
4
 
3
5
  HTTP::Cookie is a ruby library to handle HTTP cookies in a way both
@@ -20,7 +22,8 @@ The following is an incomplete list of its features:
20
22
  * It takes eTLD (effective TLD, also known as "Public Suffix") into
21
23
  account just as major browsers do, to reject cookies with an eTLD
22
24
  domain like "org", "co.jp", or "appspot.com". This feature is
23
- brought to you by the domain_name gem.
25
+ brought to you by the
26
+ [domain_name](https://github.com/knu/ruby-domain_name) gem.
24
27
 
25
28
  * The number of cookies and the size are properly capped so that a
26
29
  cookie store does not get flooded.
@@ -207,7 +210,7 @@ equivalent using HTTP::Cookie:
207
210
  guarantee that it will remain available in the future.
208
211
 
209
212
 
210
- HTTP::Cookie/CookieJar raise runtime errors to help migration, so
213
+ HTTP::Cookie/CookieJar raises runtime errors to help migration, so
211
214
  after replacing the class names, try running your test code once to
212
215
  find out how to fix your code base.
213
216
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'http/cookie'
2
3
  require 'strscan'
3
4
  require 'time'
@@ -23,7 +24,7 @@ class HTTP::Cookie::Scanner < StringScanner
23
24
  class << self
24
25
  def quote(s)
25
26
  return s unless s.match(RE_BAD_CHAR)
26
- '"' << s.gsub(/([\\"])/, "\\\\\\1") << '"'
27
+ (+'"') << s.gsub(/([\\"])/, "\\\\\\1") << '"'
27
28
  end
28
29
  end
29
30
 
@@ -32,7 +33,7 @@ class HTTP::Cookie::Scanner < StringScanner
32
33
  end
33
34
 
34
35
  def scan_dquoted
35
- ''.tap { |s|
36
+ (+'').tap { |s|
36
37
  case
37
38
  when skip(/"/)
38
39
  break
@@ -51,7 +52,7 @@ class HTTP::Cookie::Scanner < StringScanner
51
52
  end
52
53
 
53
54
  def scan_value(comma_as_separator = false)
54
- ''.tap { |s|
55
+ (+'').tap { |s|
55
56
  case
56
57
  when scan(/[^,;"]+/)
57
58
  s << matched
@@ -0,0 +1,36 @@
1
+ module HTTP::Cookie::URIParser
2
+ module_function
3
+
4
+ # Regular Expression taken from RFC 3986 Appendix B
5
+ URIREGEX = %r{
6
+ \A
7
+ (?: (?<scheme> [^:/?\#]+ ) : )?
8
+ (?: // (?<authority> [^/?\#]* ) )?
9
+ (?<path> [^?\#]* )
10
+ (?: \? (?<query> [^\#]* ) )?
11
+ (?: \# (?<fragment> .* ) )?
12
+ \z
13
+ }x
14
+
15
+ # Escape RFC 3986 "reserved" characters minus valid characters for path
16
+ # More specifically, gen-delims minus "/" / "?" / "#"
17
+ def escape_path(path)
18
+ path.sub(/\A[^?#]+/) { |p| p.gsub(/[:\[\]@]+/) { |r| CGI.escape(r) } }
19
+ end
20
+
21
+ # Parse a URI string or object, relaxing the constraints on the path component
22
+ def parse(uri)
23
+ URI(uri)
24
+ rescue URI::InvalidURIError
25
+ str = String.try_convert(uri) or
26
+ raise ArgumentError, "bad argument (expected URI object or URI string)"
27
+
28
+ m = URIREGEX.match(str) or raise
29
+
30
+ path = m[:path]
31
+ str[m.begin(:path)...m.end(:path)] = escape_path(path)
32
+ uri = URI.parse(str)
33
+ uri.__send__(:set_path, path)
34
+ uri
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  class Cookie
3
- VERSION = "1.0.5"
3
+ VERSION = "1.0.8"
4
4
  end
5
5
  end
data/lib/http/cookie.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  # :markup: markdown
2
+ # frozen_string_literal: true
2
3
  require 'http/cookie/version'
4
+ require 'http/cookie/uri_parser'
3
5
  require 'time'
4
6
  require 'uri'
5
7
  require 'domain_name'
6
8
  require 'http/cookie/ruby_compat'
9
+ require 'cgi'
7
10
 
8
11
  module HTTP
9
12
  autoload :CookieJar, 'http/cookie_jar'
@@ -86,7 +89,7 @@ class HTTP::Cookie
86
89
 
87
90
  # The Expires attribute value as a Time object.
88
91
  #
89
- # The setter method accepts a Time object, a string representation
92
+ # The setter method accepts a Time / DateTime object, a string representation
90
93
  # of date/time that Time.parse can understand, or `nil`.
91
94
  #
92
95
  # Setting this value resets #max_age to nil. When #max_age is
@@ -275,7 +278,7 @@ class HTTP::Cookie
275
278
  logger = options[:logger]
276
279
  created_at = options[:created_at]
277
280
  end
278
- origin = URI(origin)
281
+ origin = HTTP::Cookie::URIParser.parse(origin)
279
282
 
280
283
  [].tap { |cookies|
281
284
  Scanner.new(set_cookie, logger).scan_set_cookie { |name, value, attrs|
@@ -424,7 +427,7 @@ class HTTP::Cookie
424
427
  # Returns the domain, with a dot prefixed only if the domain flag is
425
428
  # on.
426
429
  def dot_domain
427
- @for_domain ? '.' << @domain : @domain
430
+ @for_domain ? (+'.') << @domain : @domain
428
431
  end
429
432
 
430
433
  # Returns the domain attribute value as a DomainName object.
@@ -455,7 +458,7 @@ class HTTP::Cookie
455
458
  @origin.nil? or
456
459
  raise ArgumentError, "origin cannot be changed once it is set"
457
460
  # Delay setting @origin because #domain= or #path= may fail
458
- origin = URI(origin)
461
+ origin = HTTP::Cookie::URIParser.parse(origin)
459
462
  if URI::HTTP === origin
460
463
  self.domain ||= origin.host
461
464
  self.path ||= (origin + './').path
@@ -490,6 +493,8 @@ class HTTP::Cookie
490
493
  def expires= t
491
494
  case t
492
495
  when nil, Time
496
+ when DateTime
497
+ t = t.to_time
493
498
  else
494
499
  t = Time.parse(t)
495
500
  end
@@ -548,7 +553,7 @@ class HTTP::Cookie
548
553
  # Tests if it is OK to accept this cookie if it is sent from a given
549
554
  # URI/URL, `uri`.
550
555
  def acceptable_from_uri?(uri)
551
- uri = URI(uri)
556
+ uri = HTTP::Cookie::URIParser.parse(uri)
552
557
  return false unless URI::HTTP === uri && uri.host
553
558
  host = DomainName.new(uri.host)
554
559
 
@@ -585,7 +590,7 @@ class HTTP::Cookie
585
590
  if @domain.nil?
586
591
  raise "cannot tell if this cookie is valid because the domain is unknown"
587
592
  end
588
- uri = URI(uri)
593
+ uri = HTTP::Cookie::URIParser.parse(uri)
589
594
  # RFC 6265 5.4
590
595
  return false if secure? && !(URI::HTTPS === uri)
591
596
  acceptable_from_uri?(uri) && HTTP::Cookie.path_match?(@path, uri.path)
@@ -594,7 +599,7 @@ class HTTP::Cookie
594
599
  # Returns a string for use in the Cookie header, i.e. `name=value`
595
600
  # or `name="value"`.
596
601
  def cookie_value
597
- "#{@name}=#{Scanner.quote(@value)}"
602
+ +"#{@name}=#{Scanner.quote(@value)}"
598
603
  end
599
604
  alias to_s cookie_value
600
605
 
@@ -18,7 +18,7 @@ class HTTP::CookieJar::AbstractStore
18
18
  require 'http/cookie_jar/%s_store' % symbol
19
19
  @@class_map.fetch(symbol)
20
20
  rescue LoadError, IndexError => e
21
- raise IndexError, 'cookie store unavailable: %s, error: %s' % symbol.inspect, e.message
21
+ raise IndexError, 'cookie store unavailable: %s, error: %s' % [symbol.inspect, e.message]
22
22
  end
23
23
  end
24
24
 
@@ -400,8 +400,6 @@ class HTTP::CookieJar
400
400
  }
401
401
  end
402
402
  else
403
- require 'cgi'
404
-
405
403
  def encode_www_form(enum)
406
404
  enum.map { |k, v| "#{CGI.escape(k)}=#{CGI.escape(v)}" }.join('&')
407
405
  end
@@ -156,7 +156,7 @@ class HTTP::CookieJar
156
156
  block_given? or return enum_for(__method__, uri)
157
157
 
158
158
  if uri
159
- uri = URI(uri)
159
+ uri = HTTP::Cookie::URIParser.parse(uri)
160
160
  return self unless URI::HTTP === uri && uri.host
161
161
  end
162
162
 
data/test/helper.rb CHANGED
@@ -7,7 +7,7 @@ module Test
7
7
  module Unit
8
8
  module Assertions
9
9
  def assert_warn(pattern, message = nil, &block)
10
- class << (output = "")
10
+ class << (output = +"")
11
11
  alias write <<
12
12
  end
13
13
  stderr, $stderr = $stderr, output
@@ -50,6 +50,6 @@ end
50
50
 
51
51
  def sleep_until(time)
52
52
  if (s = time - Time.now) > 0
53
- sleep s
53
+ sleep s + 0.01
54
54
  end
55
55
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: false
2
3
  require File.expand_path('helper', File.dirname(__FILE__))
3
4
  require 'psych' if !defined?(YAML) && RUBY_VERSION == "1.9.2"
4
5
  require 'yaml'
@@ -302,7 +303,8 @@ class TestHTTPCookie < Test::Unit::TestCase
302
303
  "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
303
304
  "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/; HttpOnly, " \
304
305
  "expired=doh; Expires=Fri, 04 Nov 2011 00:29:51 GMT; Path=/, " \
305
- "a_path=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path, " \
306
+ "a_path1=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path, " \
307
+ "a_path2=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path[], " \
306
308
  "no_path1=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT, no_expires=nope; Path=/, " \
307
309
  "no_path2=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path, " \
308
310
  "no_path3=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=, " \
@@ -313,17 +315,22 @@ class TestHTTPCookie < Test::Unit::TestCase
313
315
  "no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
314
316
 
315
317
  cookies = HTTP::Cookie.parse cookie_str, url
316
- assert_equal 15, cookies.length
318
+ assert_equal 16, cookies.length
317
319
 
318
320
  name = cookies.find { |c| c.name == 'name' }
319
321
  assert_equal "Aaron", name.value
320
322
  assert_equal "/", name.path
321
323
  assert_equal Time.at(1320539391), name.expires
322
324
 
323
- a_path = cookies.find { |c| c.name == 'a_path' }
324
- assert_equal "some_path", a_path.value
325
- assert_equal "/some_path", a_path.path
326
- assert_equal Time.at(1320539391), a_path.expires
325
+ a_path1 = cookies.find { |c| c.name == 'a_path1' }
326
+ assert_equal "some_path", a_path1.value
327
+ assert_equal "/some_path", a_path1.path
328
+ assert_equal Time.at(1320539391), a_path1.expires
329
+
330
+ a_path2 = cookies.find { |c| c.name == 'a_path2' }
331
+ assert_equal "some_path", a_path2.value
332
+ assert_equal "/some_path[]", a_path2.path
333
+ assert_equal Time.at(1320539391), a_path2.expires
327
334
 
328
335
  no_expires = cookies.find { |c| c.name == 'no_expires' }
329
336
  assert_equal "nope", no_expires.value
@@ -710,8 +717,22 @@ class TestHTTPCookie < Test::Unit::TestCase
710
717
  end
711
718
 
712
719
  def test_expiration
713
- cookie = HTTP::Cookie.new(cookie_values)
720
+ expires = Time.now + 86400
721
+ cookie = HTTP::Cookie.new(cookie_values(expires: expires))
722
+
723
+ assert_equal(expires, cookie.expires)
724
+ assert_equal false, cookie.expired?
725
+ assert_equal true, cookie.expired?(cookie.expires + 1)
726
+ assert_equal false, cookie.expired?(cookie.expires - 1)
727
+ cookie.expire!
728
+ assert_equal true, cookie.expired?
729
+ end
714
730
 
731
+ def test_expiration_using_datetime
732
+ expires = DateTime.now + 1
733
+ cookie = HTTP::Cookie.new(cookie_values(expires: expires))
734
+
735
+ assert_equal(expires.to_time, cookie.expires)
715
736
  assert_equal false, cookie.expired?
716
737
  assert_equal true, cookie.expired?(cookie.expires + 1)
717
738
  assert_equal false, cookie.expired?(cookie.expires - 1)
@@ -751,7 +772,7 @@ class TestHTTPCookie < Test::Unit::TestCase
751
772
  assert_equal 12, cookie.max_age
752
773
 
753
774
  cookie.max_age = -3
754
- assert_equal -3, cookie.max_age
775
+ assert_equal(-3, cookie.max_age)
755
776
  end
756
777
 
757
778
  def test_session
@@ -941,6 +962,10 @@ class TestHTTPCookie < Test::Unit::TestCase
941
962
  cookie.origin = URI.parse('http://www.example.com/')
942
963
  }
943
964
 
965
+ cookie = HTTP::Cookie.new('a', 'b')
966
+ cookie.origin = HTTP::Cookie::URIParser.parse('http://example.com/path[]/')
967
+ assert_equal '/path[]/', cookie.path
968
+
944
969
  cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com')
945
970
  cookie.origin = URI.parse('http://example.org/')
946
971
  assert_equal false, cookie.acceptable?
@@ -1006,7 +1031,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1006
1031
  'https://www.example.com/dir2/test.html',
1007
1032
  ]
1008
1033
  },
1009
- HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2/',
1034
+ HTTP::Cookie.parse('a3=b; domain=example.com; path=/dir2/',
1010
1035
  URI('http://example.com/dir/file.html')).first => {
1011
1036
  true => [
1012
1037
  'https://example.com/dir2/test.html',
@@ -1022,7 +1047,19 @@ class TestHTTPCookie < Test::Unit::TestCase
1022
1047
  'file:///dir2/test.html',
1023
1048
  ]
1024
1049
  },
1025
- HTTP::Cookie.parse('a4=b; secure',
1050
+ HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2[]/',
1051
+ HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html')).first => {
1052
+ true => [
1053
+ HTTP::Cookie::URIParser.parse('https://example.com/dir2[]/file.html'),
1054
+ HTTP::Cookie::URIParser.parse('http://example.com/dir2[]/file.html'),
1055
+ ],
1056
+ false => [
1057
+ HTTP::Cookie::URIParser.parse('https://example.com/dir[]/file.html'),
1058
+ HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html'),
1059
+ 'file:///dir2/test.html',
1060
+ ]
1061
+ },
1062
+ HTTP::Cookie.parse('a5=b; secure',
1026
1063
  URI('https://example.com/dir/file.html')).first => {
1027
1064
  true => [
1028
1065
  'https://example.com/dir/test.html',
@@ -1034,7 +1071,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1034
1071
  'file:///dir2/test.html',
1035
1072
  ]
1036
1073
  },
1037
- HTTP::Cookie.parse('a5=b',
1074
+ HTTP::Cookie.parse('a6=b',
1038
1075
  URI('https://example.com/')).first => {
1039
1076
  true => [
1040
1077
  'https://example.com',
@@ -1043,7 +1080,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1043
1080
  'file:///',
1044
1081
  ]
1045
1082
  },
1046
- HTTP::Cookie.parse('a6=b; path=/dir',
1083
+ HTTP::Cookie.parse('a7=b; path=/dir',
1047
1084
  'http://example.com/dir/file.html').first => {
1048
1085
  true => [
1049
1086
  'http://example.com/dir',
@@ -1069,7 +1106,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1069
1106
  hash.each { |expected, urls|
1070
1107
  urls.each { |url|
1071
1108
  assert_equal expected, cookie.valid_for_uri?(url), '%s: %s' % [cookie.name, url]
1072
- assert_equal expected, cookie.valid_for_uri?(URI(url)), "%s: URI(%s)" % [cookie.name, url]
1109
+ assert_equal expected, cookie.valid_for_uri?(HTTP::Cookie::URIParser.parse(url)), "%s: URI(%s)" % [cookie.name, url]
1073
1110
  }
1074
1111
  }
1075
1112
  }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  require File.expand_path('helper', File.dirname(__FILE__))
2
3
  require 'tmpdir'
3
4
 
@@ -9,6 +10,13 @@ module TestHTTPCookieJar
9
10
  }
10
11
  end
11
12
 
13
+ def test_nonexistent_store_in_config
14
+ expected = /cookie store unavailable: :nonexistent, error: (cannot load|no such file to load) .*nonexistent_store/
15
+ assert_raise_with_message(ArgumentError, expected) {
16
+ HTTP::CookieJar.new(store: :nonexistent)
17
+ }
18
+ end
19
+
12
20
  def test_erroneous_store
13
21
  Dir.mktmpdir { |dir|
14
22
  Dir.mkdir(File.join(dir, 'http'))
@@ -465,7 +473,7 @@ module TestHTTPCookieJar
465
473
  end
466
474
 
467
475
  def test_save_and_read_cookiestxt
468
- url = URI 'http://rubyforge.org/foo/'
476
+ url = HTTP::Cookie::URIParser.parse('https://rubyforge.org/foo[]/')
469
477
 
470
478
  # Add one cookie with an expiration date in the future
471
479
  cookie = HTTP::Cookie.new(cookie_values)
@@ -474,7 +482,7 @@ module TestHTTPCookieJar
474
482
  :expires => nil))
475
483
  cookie2 = HTTP::Cookie.new(cookie_values(:name => 'Baz',
476
484
  :value => 'Foo#Baz',
477
- :path => '/foo/',
485
+ :path => '/foo[]/',
478
486
  :for_domain => false))
479
487
  h_cookie = HTTP::Cookie.new(cookie_values(:name => 'Quux',
480
488
  :value => 'Foo#Quux',
@@ -523,7 +531,7 @@ module TestHTTPCookieJar
523
531
  assert_equal 'Foo#Baz', cookie.value
524
532
  assert_equal 'rubyforge.org', cookie.domain
525
533
  assert_equal false, cookie.for_domain
526
- assert_equal '/foo/', cookie.path
534
+ assert_equal '/foo[]/', cookie.path
527
535
  assert_equal false, cookie.httponly?
528
536
  when 'Quux'
529
537
  assert_equal 'Foo#Quux', cookie.value
@@ -656,6 +664,34 @@ module TestHTTPCookieJar
656
664
  assert_equal(0, @jar.cookies(url).length)
657
665
  end
658
666
 
667
+ def test_non_rfc3986_compliant_paths
668
+ url = HTTP::Cookie::URIParser.parse('http://RubyForge.org/login[]')
669
+
670
+ values = cookie_values(:path => "/login[]", :expires => nil, :origin => url)
671
+
672
+ # Add one cookie with an expiration date in the future
673
+ cookie = HTTP::Cookie.new(values)
674
+ @jar.add(cookie)
675
+ assert_equal(1, @jar.cookies(url).length)
676
+
677
+ # Add a second cookie
678
+ @jar.add(HTTP::Cookie.new(values.merge( :name => 'Baz' )))
679
+ assert_equal(2, @jar.cookies(url).length)
680
+
681
+ # Make sure we don't get the cookie in a different path
682
+ assert_equal(0, @jar.cookies(HTTP::Cookie::URIParser.parse('http://RubyForge.org/hello[]')).length)
683
+ assert_equal(0, @jar.cookies(HTTP::Cookie::URIParser.parse('http://RubyForge.org/')).length)
684
+
685
+ # Expire the first cookie
686
+ @jar.add(HTTP::Cookie.new(values.merge( :expires => Time.now - (10 * 86400))))
687
+ assert_equal(1, @jar.cookies(url).length)
688
+
689
+ # Expire the second cookie
690
+ @jar.add(HTTP::Cookie.new(values.merge( :name => 'Baz',
691
+ :expires => Time.now - (10 * 86400))))
692
+ assert_equal(0, @jar.cookies(url).length)
693
+ end
694
+
659
695
  def test_ssl_cookies
660
696
  # thanks to michal "ocher" ochman for reporting the bug responsible for this test.
661
697
  values = cookie_values(:expires => nil)
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: 1.0.5
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-05-25 00:00:00.000000000 Z
14
+ date: 2024-12-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: domain_name
@@ -127,6 +127,7 @@ extra_rdoc_files:
127
127
  - README.md
128
128
  - LICENSE.txt
129
129
  files:
130
+ - ".github/CODEOWNERS"
130
131
  - ".github/workflows/ci.yml"
131
132
  - ".gitignore"
132
133
  - CHANGELOG.md
@@ -139,6 +140,7 @@ files:
139
140
  - lib/http/cookie.rb
140
141
  - lib/http/cookie/ruby_compat.rb
141
142
  - lib/http/cookie/scanner.rb
143
+ - lib/http/cookie/uri_parser.rb
142
144
  - lib/http/cookie/version.rb
143
145
  - lib/http/cookie_jar.rb
144
146
  - lib/http/cookie_jar/abstract_saver.rb
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  - !ruby/object:Gem::Version
172
174
  version: '0'
173
175
  requirements: []
174
- rubygems_version: 3.3.14
176
+ rubygems_version: 3.5.22
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: A Ruby library to handle HTTP Cookies based on RFC 6265