http-cookie 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e3fc7cc6e374fa6bdd53c2a32cae8b8856615df4aad76fe496ab6375738652e
4
- data.tar.gz: 0132bb41158fa3bf84a0adf2fcf7226115a1126efbc12c879f465a8c2114215b
3
+ metadata.gz: fd2affae74acb780842ead781a250bf2fe174fd034417391224ded71767cc08a
4
+ data.tar.gz: 77f5ed5bdf3b14002399d237e3d86eb655f2d27da1c3aafd5725338565c24b08
5
5
  SHA512:
6
- metadata.gz: 341c0b9947ed005f8c73030ad7b5380aa19d76cbfc2f3f09ac69207a9a5b33e62f0094f6b68b98ad839f110c565f7afc08a9ff504c82affe736a8bcb55908e05
7
- data.tar.gz: c4346ce6bae86a394c72b38f079c3c272205df3b7453c630e1dc3fc1ae7dec7ee0f652c9b5f2b12151fb6b7b402a5fbc41b832c051cf17102bd1cd584f72b461
6
+ metadata.gz: 5121ba37a869a8aa52c2efbc2ac3909715883d49203374c8997a3ceeceb84b15e674c77b5ccb0ad5a8cfcea593bfc8c707a96ff4b3ee7a5634302195e8a50ee5
7
+ data.tar.gz: 8cb0b6b1ed0b5e9f952031b677a3d8e28d2d14c4a4036e335bfe3ce433743408ce6d1aaa8a23545777328a31cf1e095fc85dde84ddbc056e2ef4fc1e6d2e83be
@@ -0,0 +1 @@
1
+ * @knu
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - "*"
10
+
11
+ jobs:
12
+ test:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu]
17
+ # We still kind of support Ruby 1.8.7
18
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3", "head", "jruby"]
19
+
20
+ name: >-
21
+ ${{matrix.os}}:ruby-${{matrix.ruby}}
22
+ runs-on: ${{matrix.os}}-latest
23
+ continue-on-error: ${{matrix.ruby == 'head' || matrix.ruby == 'jruby'}}
24
+
25
+ steps:
26
+ - name: Check out
27
+ uses: actions/checkout@v4
28
+
29
+ - name: Set up ruby and bundle
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{matrix.ruby}}
33
+ bundler-cache: true
34
+
35
+ - name: Run rake
36
+ run: |
37
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## Unreleased
1
+ ## 1.0.5 (2022-05-25)
2
+
3
+ - Silence SQLite3 warnings
4
+
5
+ ## 1.0.4 (2021-06-07)
2
6
 
3
7
  - Support Mozilla's cookie storage format up to version 7.
4
8
 
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
 
data/http-cookie.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
25
25
  gem.extra_rdoc_files = ['README.md', 'LICENSE.txt']
26
26
 
27
27
  gem.add_runtime_dependency("domain_name", ["~> 0.5"])
28
- gem.add_development_dependency("sqlite3", ["~> 1.3.3"]) unless defined?(JRUBY_VERSION)
28
+ gem.add_development_dependency("sqlite3", ["~> 1.3"]) unless defined?(JRUBY_VERSION)
29
29
  gem.add_development_dependency("bundler", [">= 1.2.0"])
30
30
  gem.add_development_dependency("test-unit", [">= 2.4.3", *("< 3" if RUBY_VERSION < "1.9")])
31
31
  gem.add_development_dependency("rake", [">= 0.9.2.2", *("< 11" if RUBY_VERSION < "1.9")])
@@ -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.4"
3
+ VERSION = "1.0.6"
4
4
  end
5
5
  end
data/lib/http/cookie.rb CHANGED
@@ -1,5 +1,7 @@
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'
@@ -275,7 +277,7 @@ class HTTP::Cookie
275
277
  logger = options[:logger]
276
278
  created_at = options[:created_at]
277
279
  end
278
- origin = URI(origin)
280
+ origin = HTTP::Cookie::URIParser.parse(origin)
279
281
 
280
282
  [].tap { |cookies|
281
283
  Scanner.new(set_cookie, logger).scan_set_cookie { |name, value, attrs|
@@ -424,7 +426,7 @@ class HTTP::Cookie
424
426
  # Returns the domain, with a dot prefixed only if the domain flag is
425
427
  # on.
426
428
  def dot_domain
427
- @for_domain ? '.' << @domain : @domain
429
+ @for_domain ? (+'.') << @domain : @domain
428
430
  end
429
431
 
430
432
  # Returns the domain attribute value as a DomainName object.
@@ -455,7 +457,7 @@ class HTTP::Cookie
455
457
  @origin.nil? or
456
458
  raise ArgumentError, "origin cannot be changed once it is set"
457
459
  # Delay setting @origin because #domain= or #path= may fail
458
- origin = URI(origin)
460
+ origin = HTTP::Cookie::URIParser.parse(origin)
459
461
  if URI::HTTP === origin
460
462
  self.domain ||= origin.host
461
463
  self.path ||= (origin + './').path
@@ -548,7 +550,7 @@ class HTTP::Cookie
548
550
  # Tests if it is OK to accept this cookie if it is sent from a given
549
551
  # URI/URL, `uri`.
550
552
  def acceptable_from_uri?(uri)
551
- uri = URI(uri)
553
+ uri = HTTP::Cookie::URIParser.parse(uri)
552
554
  return false unless URI::HTTP === uri && uri.host
553
555
  host = DomainName.new(uri.host)
554
556
 
@@ -585,7 +587,7 @@ class HTTP::Cookie
585
587
  if @domain.nil?
586
588
  raise "cannot tell if this cookie is valid because the domain is unknown"
587
589
  end
588
- uri = URI(uri)
590
+ uri = HTTP::Cookie::URIParser.parse(uri)
589
591
  # RFC 6265 5.4
590
592
  return false if secure? && !(URI::HTTPS === uri)
591
593
  acceptable_from_uri?(uri) && HTTP::Cookie.path_match?(@path, uri.path)
@@ -594,7 +596,7 @@ class HTTP::Cookie
594
596
  # Returns a string for use in the Cookie header, i.e. `name=value`
595
597
  # or `name="value"`.
596
598
  def cookie_value
597
- "#{@name}=#{Scanner.quote(@value)}"
599
+ +"#{@name}=#{Scanner.quote(@value)}"
598
600
  end
599
601
  alias to_s cookie_value
600
602
 
@@ -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
 
@@ -136,7 +136,7 @@ class HTTP::CookieJar
136
136
 
137
137
  # Returns the schema version of the database.
138
138
  def schema_version
139
- @schema_version ||= @db.execute("PRAGMA user_version").first[0]
139
+ @schema_version ||= @db.execute("PRAGMA user_version").first["user_version"]
140
140
  rescue SQLite3::SQLException
141
141
  @logger.warn "couldn't get schema version!" if @logger
142
142
  return nil
@@ -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,5 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: false
2
3
  require File.expand_path('helper', File.dirname(__FILE__))
4
+ require 'psych' if !defined?(YAML) && RUBY_VERSION == "1.9.2"
5
+ require 'yaml'
3
6
 
4
7
  class TestHTTPCookie < Test::Unit::TestCase
5
8
  def setup
@@ -300,7 +303,8 @@ class TestHTTPCookie < Test::Unit::TestCase
300
303
  "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
301
304
  "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/; HttpOnly, " \
302
305
  "expired=doh; Expires=Fri, 04 Nov 2011 00:29:51 GMT; Path=/, " \
303
- "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[], " \
304
308
  "no_path1=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT, no_expires=nope; Path=/, " \
305
309
  "no_path2=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path, " \
306
310
  "no_path3=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=, " \
@@ -311,17 +315,22 @@ class TestHTTPCookie < Test::Unit::TestCase
311
315
  "no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
312
316
 
313
317
  cookies = HTTP::Cookie.parse cookie_str, url
314
- assert_equal 15, cookies.length
318
+ assert_equal 16, cookies.length
315
319
 
316
320
  name = cookies.find { |c| c.name == 'name' }
317
321
  assert_equal "Aaron", name.value
318
322
  assert_equal "/", name.path
319
323
  assert_equal Time.at(1320539391), name.expires
320
324
 
321
- a_path = cookies.find { |c| c.name == 'a_path' }
322
- assert_equal "some_path", a_path.value
323
- assert_equal "/some_path", a_path.path
324
- 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
325
334
 
326
335
  no_expires = cookies.find { |c| c.name == 'no_expires' }
327
336
  assert_equal "nope", no_expires.value
@@ -749,7 +758,7 @@ class TestHTTPCookie < Test::Unit::TestCase
749
758
  assert_equal 12, cookie.max_age
750
759
 
751
760
  cookie.max_age = -3
752
- assert_equal -3, cookie.max_age
761
+ assert_equal(-3, cookie.max_age)
753
762
  end
754
763
 
755
764
  def test_session
@@ -939,6 +948,10 @@ class TestHTTPCookie < Test::Unit::TestCase
939
948
  cookie.origin = URI.parse('http://www.example.com/')
940
949
  }
941
950
 
951
+ cookie = HTTP::Cookie.new('a', 'b')
952
+ cookie.origin = HTTP::Cookie::URIParser.parse('http://example.com/path[]/')
953
+ assert_equal '/path[]/', cookie.path
954
+
942
955
  cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com')
943
956
  cookie.origin = URI.parse('http://example.org/')
944
957
  assert_equal false, cookie.acceptable?
@@ -1004,7 +1017,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1004
1017
  'https://www.example.com/dir2/test.html',
1005
1018
  ]
1006
1019
  },
1007
- HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2/',
1020
+ HTTP::Cookie.parse('a3=b; domain=example.com; path=/dir2/',
1008
1021
  URI('http://example.com/dir/file.html')).first => {
1009
1022
  true => [
1010
1023
  'https://example.com/dir2/test.html',
@@ -1020,7 +1033,19 @@ class TestHTTPCookie < Test::Unit::TestCase
1020
1033
  'file:///dir2/test.html',
1021
1034
  ]
1022
1035
  },
1023
- HTTP::Cookie.parse('a4=b; secure',
1036
+ HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2[]/',
1037
+ HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html')).first => {
1038
+ true => [
1039
+ HTTP::Cookie::URIParser.parse('https://example.com/dir2[]/file.html'),
1040
+ HTTP::Cookie::URIParser.parse('http://example.com/dir2[]/file.html'),
1041
+ ],
1042
+ false => [
1043
+ HTTP::Cookie::URIParser.parse('https://example.com/dir[]/file.html'),
1044
+ HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html'),
1045
+ 'file:///dir2/test.html',
1046
+ ]
1047
+ },
1048
+ HTTP::Cookie.parse('a5=b; secure',
1024
1049
  URI('https://example.com/dir/file.html')).first => {
1025
1050
  true => [
1026
1051
  'https://example.com/dir/test.html',
@@ -1032,7 +1057,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1032
1057
  'file:///dir2/test.html',
1033
1058
  ]
1034
1059
  },
1035
- HTTP::Cookie.parse('a5=b',
1060
+ HTTP::Cookie.parse('a6=b',
1036
1061
  URI('https://example.com/')).first => {
1037
1062
  true => [
1038
1063
  'https://example.com',
@@ -1041,7 +1066,7 @@ class TestHTTPCookie < Test::Unit::TestCase
1041
1066
  'file:///',
1042
1067
  ]
1043
1068
  },
1044
- HTTP::Cookie.parse('a6=b; path=/dir',
1069
+ HTTP::Cookie.parse('a7=b; path=/dir',
1045
1070
  'http://example.com/dir/file.html').first => {
1046
1071
  true => [
1047
1072
  'http://example.com/dir',
@@ -1067,12 +1092,22 @@ class TestHTTPCookie < Test::Unit::TestCase
1067
1092
  hash.each { |expected, urls|
1068
1093
  urls.each { |url|
1069
1094
  assert_equal expected, cookie.valid_for_uri?(url), '%s: %s' % [cookie.name, url]
1070
- assert_equal expected, cookie.valid_for_uri?(URI(url)), "%s: URI(%s)" % [cookie.name, url]
1095
+ assert_equal expected, cookie.valid_for_uri?(HTTP::Cookie::URIParser.parse(url)), "%s: URI(%s)" % [cookie.name, url]
1071
1096
  }
1072
1097
  }
1073
1098
  }
1074
1099
  end
1075
1100
 
1101
+ if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
1102
+ private def load_yaml(yaml)
1103
+ YAML.safe_load(yaml, :permitted_classes => %w[Time HTTP::Cookie Mechanize::Cookie DomainName], :aliases => true)
1104
+ end
1105
+ else
1106
+ private def load_yaml(yaml)
1107
+ YAML.load(yaml)
1108
+ end
1109
+ end
1110
+
1076
1111
  def test_yaml_expires
1077
1112
  require 'yaml'
1078
1113
  cookie = HTTP::Cookie.new(cookie_values)
@@ -1080,29 +1115,29 @@ class TestHTTPCookie < Test::Unit::TestCase
1080
1115
  assert_equal false, cookie.session?
1081
1116
  assert_equal nil, cookie.max_age
1082
1117
 
1083
- ycookie = YAML.load(cookie.to_yaml)
1118
+ ycookie = load_yaml(cookie.to_yaml)
1084
1119
  assert_equal false, ycookie.session?
1085
1120
  assert_equal nil, ycookie.max_age
1086
1121
  assert_in_delta cookie.expires, ycookie.expires, 1
1087
1122
 
1088
1123
  cookie.expires = nil
1089
- ycookie = YAML.load(cookie.to_yaml)
1124
+ ycookie = load_yaml(cookie.to_yaml)
1090
1125
  assert_equal true, ycookie.session?
1091
1126
  assert_equal nil, ycookie.max_age
1092
1127
 
1093
1128
  cookie.expires = Time.now + 3600
1094
- ycookie = YAML.load(cookie.to_yaml)
1129
+ ycookie = load_yaml(cookie.to_yaml)
1095
1130
  assert_equal false, ycookie.session?
1096
1131
  assert_equal nil, ycookie.max_age
1097
1132
  assert_in_delta cookie.expires, ycookie.expires, 1
1098
1133
 
1099
1134
  cookie.max_age = 3600
1100
- ycookie = YAML.load(cookie.to_yaml)
1135
+ ycookie = load_yaml(cookie.to_yaml)
1101
1136
  assert_equal false, ycookie.session?
1102
1137
  assert_in_delta cookie.created_at + 3600, ycookie.expires, 1
1103
1138
 
1104
1139
  cookie.max_age = nil
1105
- ycookie = YAML.load(cookie.to_yaml)
1140
+ ycookie = load_yaml(cookie.to_yaml)
1106
1141
  assert_equal true, ycookie.session?
1107
1142
  assert_equal nil, ycookie.expires
1108
1143
  end
@@ -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,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-cookie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  - Aaron Patterson
9
9
  - Eric Hodel
10
10
  - Mike Dalessio
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-06-07 00:00:00.000000000 Z
14
+ date: 2024-06-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: domain_name
@@ -33,14 +33,14 @@ dependencies:
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: 1.3.3
36
+ version: '1.3'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 1.3.3
43
+ version: '1.3'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: bundler
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -127,8 +127,9 @@ extra_rdoc_files:
127
127
  - README.md
128
128
  - LICENSE.txt
129
129
  files:
130
+ - ".github/CODEOWNERS"
131
+ - ".github/workflows/ci.yml"
130
132
  - ".gitignore"
131
- - ".travis.yml"
132
133
  - CHANGELOG.md
133
134
  - Gemfile
134
135
  - LICENSE.txt
@@ -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
@@ -156,7 +158,7 @@ homepage: https://github.com/sparklemotion/http-cookie
156
158
  licenses:
157
159
  - MIT
158
160
  metadata: {}
159
- post_install_message:
161
+ post_install_message:
160
162
  rdoc_options: []
161
163
  require_paths:
162
164
  - lib
@@ -171,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  - !ruby/object:Gem::Version
172
174
  version: '0'
173
175
  requirements: []
174
- rubygems_version: 3.2.11
175
- signing_key:
176
+ rubygems_version: 3.5.9
177
+ signing_key:
176
178
  specification_version: 4
177
179
  summary: A Ruby library to handle HTTP Cookies based on RFC 6265
178
180
  test_files:
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 1.8.7
6
- - ree
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1
10
- - 2.2
11
- - 2.3.0
12
- - ruby-head
13
- - jruby-1.7
14
- - jruby-9
15
- - rbx-2
16
- matrix:
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: rbx-2
20
- before_install:
21
- - gem update bundler