http-cookie 1.0.0.pre1 → 1.0.0.pre2

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
  SHA1:
3
- metadata.gz: 9f5ccaec04a2b731f1120d21079f05fda32dc05f
4
- data.tar.gz: aea993fb843b5218522f7a12adf189112dd8a477
3
+ metadata.gz: 653d322460f46234180a90aed35776cd7cd8de38
4
+ data.tar.gz: 14c9c551e73f83be713b128d4ae0a0cd0211d9f0
5
5
  SHA512:
6
- metadata.gz: f02c9afbb827b9a35e2417e4104488d3cfc237ac9ec8007c6b77b96b61c2b5c1f3a74f10660211ff1e4e2ee5000f28ddb1052148ce3cba5ccc1d2d3d49e135a8
7
- data.tar.gz: 8316457b65faeb9d19449bf49e11b920d53d9c5c8e37edf8d99d02b32fcf30350dff5c270cad654a8e0d4dcc45950894d59496450a7fde2f14e339a1b5b0d077
6
+ metadata.gz: 528f89eca80703fec30058de9b9772fc0fb83962d6aa17fe07977b8cbb109fe62f63989097520d955f8b70576bc63ea0c3815195d2d6717bfe1d46a87257cfe4
7
+ data.tar.gz: 4bf6f20da6f6dc7bfe5ec5980c7298f70c1ebc39024abad55b47d8c9b897d5dfc73f2a4216324ac0e6d884f930e6b401e57cefde0666dc2f88079d0508348b79
data/README.md CHANGED
@@ -111,6 +111,19 @@ equivalent using `HTTP::Cookie`:
111
111
  # after
112
112
  jar.save(file)
113
113
 
114
+ - `Mechanize::CookieJar#jar`
115
+
116
+ There is no direct access to the internal hash in
117
+ `HTTP::CookieJar` since it has introduced an abstract storage
118
+ layer. If you want to tweak the internals of the hash storage,
119
+ try creating a new storage class referring to the default storage
120
+ class `HTTP::CookieJar::HashStore`.
121
+
122
+ If you desperately need it you can access it by
123
+ `jar.store.instance_variable_get(:@jar)`, but there is no
124
+ guarantee that it will remain available in the future.
125
+
126
+
114
127
  `HTTP::Cookie`/`CookieJar` raise runtime errors to help migration, so
115
128
  after replacing the class names, try running your test code once to
116
129
  find out how to fix your code base.
@@ -128,7 +141,7 @@ Trying to load a YAML file saved by `HTTP::CookieJar` with
128
141
  `Mechanize::CookieJar` will fail in runtime error.
129
142
 
130
143
  On the other hand, there has been (and will ever be) no change in the
131
- cookies.txt format, so use it instead if compatibility is required.
144
+ cookies.txt format, so use it instead if compatibility is significant.
132
145
 
133
146
  ## Contributing
134
147
 
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
22
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
23
  gem.require_paths = ["lib"]
24
+ gem.extra_rdoc_files = ['README.md', 'LICENSE.txt']
24
25
 
25
26
  gem.add_runtime_dependency("domain_name", ["~> 0.5"])
26
27
  gem.add_development_dependency("bundler", [">= 1.2.0"])
@@ -13,8 +13,7 @@ if RUBY_VERSION < "1.9.3"
13
13
  begin
14
14
  URI(URI(''))
15
15
  rescue
16
- # :nodoc:
17
- def URI(url)
16
+ def URI(url) # :nodoc:
18
17
  url.is_a?(URI) ? url : URI.parse(url)
19
18
  end
20
19
  end
@@ -199,15 +198,32 @@ class HTTP::Cookie
199
198
  autoload :Scanner, 'http/cookie/scanner'
200
199
 
201
200
  class << self
202
- # Normalizes a given path. If it is empty or it is a relative
203
- # path, the root path '/' is returned.
201
+ # Tests if +target_path+ is under +base_path+ as described in RFC
202
+ # 6265 5.1.4. +base_path+ must be an absolute path.
203
+ # +target_path+ may be empty, in which case it is treated as the
204
+ # root path.
204
205
  #
205
- # If a URI object is given, returns a new URI object with the path
206
- # part normalized.
207
- def normalize_path(path)
208
- return path + normalize_path(path.path) if URI === path
206
+ # e.g.
207
+ #
208
+ # path_match?('/admin/', '/admin/index') == true
209
+ # path_match?('/admin/', '/Admin/index') == false
210
+ # path_match?('/admin/', '/admin/') == true
211
+ # path_match?('/admin/', '/admin') == false
212
+ #
213
+ # path_match?('/admin', '/admin') == true
214
+ # path_match?('/admin', '/Admin') == false
215
+ # path_match?('/admin', '/admins') == false
216
+ # path_match?('/admin', '/admin/') == true
217
+ # path_match?('/admin', '/admin/index') == true
218
+ def path_match?(base_path, target_path)
219
+ base_path.start_with?('/') or return false
209
220
  # RFC 6265 5.1.4
210
- path.start_with?('/') ? path : '/'
221
+ bsize = base_path.size
222
+ tsize = target_path.size
223
+ return bsize == 1 if tsize == 0 # treat empty target_path as "/"
224
+ return false unless target_path.start_with?(base_path)
225
+ return true if bsize == tsize || base_path.end_with?('/')
226
+ target_path[bsize] == ?/
211
227
  end
212
228
 
213
229
  # Parses a Set-Cookie header value `set_cookie` into an array of
@@ -233,10 +249,25 @@ class HTTP::Cookie
233
249
  #
234
250
  # `logger`
235
251
  # : Logger object useful for debugging
236
- def parse(set_cookie, options = nil, *_, &block)
237
- _.empty? && !options.is_a?(String) or
238
- raise ArgumentError, 'HTTP::Cookie equivalent for Mechanize::Cookie.parse(uri, set_cookie[, log]) is HTTP::Cookie.parse(set_cookie, :origin => uri[, :logger => log]).'
239
-
252
+ #
253
+ # ### Compatibility Note for Mechanize::Cookie users
254
+ #
255
+ # * Order of parameters is a slightly different in
256
+ # `HTTP::Cookie.parse`. Compare these:
257
+ #
258
+ # Mechanize::Cookie.parse(uri, set_cookie[, log])
259
+ #
260
+ # HTTP::Cookie.parse(set_cookie, :origin => uri[, :logger => # log])
261
+ #
262
+ # * `HTTP::Cookie.parse` does not yield nil nor include nil in an
263
+ # returned array. It simply ignores unparsable parts.
264
+ #
265
+ # * `HTTP::Cookie.parse` is made to follow RFC 6265 to the extent
266
+ # not terribly breaking interoperability with broken
267
+ # implementations. In particular, it is capable of parsing
268
+ # cookie definitions containing double-quotes just as
269
+ # naturally expected.
270
+ def parse(set_cookie, options = nil, &block)
240
271
  if options
241
272
  logger = options[:logger]
242
273
  origin = options[:origin] and origin = URI(origin)
@@ -355,11 +386,6 @@ class HTTP::Cookie
355
386
  @domain = @domain_name.hostname
356
387
  end
357
388
 
358
- # Used to exist in Mechanize::CookieJar. Use #domain=().
359
- def set_domain(domain)
360
- raise NoMethodError, 'HTTP::Cookie equivalent for Mechanize::CookieJar#set_domain() is #domain=().'
361
- end
362
-
363
389
  # Returns the domain attribute value as a DomainName object.
364
390
  attr_reader :domain_name
365
391
 
@@ -377,7 +403,7 @@ class HTTP::Cookie
377
403
  def path=(path)
378
404
  path = check_string_type(path) or
379
405
  raise TypeError, "#{path.class} is not a String"
380
- @path = HTTP::Cookie.normalize_path(path)
406
+ @path = path.start_with?('/') ? path : '/'
381
407
  end
382
408
 
383
409
  attr_reader :origin
@@ -388,7 +414,7 @@ class HTTP::Cookie
388
414
  raise ArgumentError, "origin cannot be changed once it is set"
389
415
  origin = URI(origin)
390
416
  self.domain ||= origin.host
391
- self.path ||= (HTTP::Cookie.normalize_path(origin) + './').path
417
+ self.path ||= (origin + './').path
392
418
  acceptable_from_uri?(origin) or
393
419
  raise ArgumentError, "unacceptable cookie sent from URI #{origin}"
394
420
  @origin = origin
@@ -504,7 +530,7 @@ class HTTP::Cookie
504
530
  end
505
531
  uri = URI(uri)
506
532
  return false if secure? && !(URI::HTTPS === uri)
507
- acceptable_from_uri?(uri) && HTTP::Cookie.normalize_path(uri.path).start_with?(@path)
533
+ acceptable_from_uri?(uri) && HTTP::Cookie.path_match?(@path, uri.path)
508
534
  end
509
535
 
510
536
  # Returns a string for use in a Cookie header value,
@@ -528,7 +554,7 @@ class HTTP::Cookie
528
554
  if @for_domain || @domain != DomainName.new(origin.host).hostname
529
555
  string << "; Domain=#{@domain}"
530
556
  end
531
- if (HTTP::Cookie.normalize_path(origin) + './').path != @path
557
+ if (origin + './').path != @path
532
558
  string << "; Path=#{@path}"
533
559
  end
534
560
  if @max_age
@@ -1,5 +1,5 @@
1
1
  module HTTP
2
2
  class Cookie
3
- VERSION = "1.0.0.pre1"
3
+ VERSION = "1.0.0.pre2"
4
4
  end
5
5
  end
@@ -33,10 +33,25 @@ class HTTP::CookieJar
33
33
  # Adds a +cookie+ to the jar and return self. If a given cookie has
34
34
  # no domain or path attribute values and the origin is unknown,
35
35
  # ArgumentError is raised.
36
- def add(cookie, *_)
37
- _.empty? or
38
- raise ArgumentError, 'HTTP::Cookie equivalent for Mechanize::CookieJar#add(uri, cookie) is #add(cookie) after setting cookie.origin = uri.'
39
-
36
+ #
37
+ # ### Compatibility Note for Mechanize::Cookie users
38
+ #
39
+ # In HTTP::Cookie, each cookie object can store its origin URI
40
+ # (cf. #origin). While the origin URI of a cookie can be set
41
+ # manually by #origin=, one is typically given in its generation.
42
+ # To be more specific, HTTP::Cookie.new and HTTP::Cookie.parse both
43
+ # take an :origin option.
44
+ #
45
+ # `HTTP::Cookie.parse`. Compare these:
46
+ #
47
+ # # Mechanize::Cookie
48
+ # jar.add(origin, cookie)
49
+ # jar.add!(cookie) # no acceptance check is performed
50
+ #
51
+ # # HTTP::Cookie
52
+ # jar.origin = origin # if it doesn't have one
53
+ # jar.add(cookie) # acceptance check is performed
54
+ def add(cookie)
40
55
  if cookie.domain.nil? || cookie.path.nil?
41
56
  raise ArgumentError, "a cookie with unknown domain or path cannot be added"
42
57
  end
@@ -46,11 +61,6 @@ class HTTP::CookieJar
46
61
  end
47
62
  alias << add
48
63
 
49
- # Used to exist in Mechanize::CookieJar. Use #add().
50
- def add!(cookie)
51
- raise NoMethodError, 'HTTP::Cookie equivalent for Mechanize::CookieJar#add!() is #add().'
52
- end
53
-
54
64
  # Gets an array of cookies that should be sent for the URL/URI.
55
65
  def cookies(url)
56
66
  now = Time.now
@@ -156,11 +166,6 @@ class HTTP::CookieJar
156
166
  self
157
167
  end
158
168
 
159
- # Used to exist in Mechanize::CookieJar. Use #save().
160
- def save_as(*args)
161
- raise NoMethodError, 'HTTP::Cookie equivalent for Mechanize::CookieJar#save_as() is #save().'
162
- end
163
-
164
169
  # call-seq:
165
170
  # jar.load(filename_or_io, **options)
166
171
  # jar.load(filename_or_io, format = :yaml, **options)
@@ -223,11 +228,6 @@ class HTTP::CookieJar
223
228
  self
224
229
  end
225
230
 
226
- # Used to exist in Mechanize::CookieJar. Use #clear().
227
- def clear!
228
- raise NoMethodError, 'HTTP::Cookie equivalent for Mechanize::CookieJar#clear!() is #clear().'
229
- end
230
-
231
231
  # Removes expired cookies and return self.
232
232
  def cleanup(session = false)
233
233
  @store.cleanup session
@@ -1,10 +1,12 @@
1
1
  require 'http/cookie_jar'
2
2
 
3
+ # :stopdoc:
3
4
  class Array
4
5
  def sort_by!(&block)
5
6
  replace(sort_by(&block))
6
7
  end unless method_defined?(:sort_by!)
7
8
  end
9
+ # :startdoc:
8
10
 
9
11
  class HTTP::CookieJar
10
12
  class HashStore < AbstractStore
@@ -52,11 +54,11 @@ class HTTP::CookieJar
52
54
  def each(uri = nil)
53
55
  if uri
54
56
  thost = DomainName.new(uri.host)
55
- tpath = HTTP::Cookie.normalize_path(uri.path)
57
+ tpath = uri.path
56
58
  @jar.each { |domain, paths|
57
59
  next unless thost.cookie_domain?(domain)
58
60
  paths.each { |path, hash|
59
- next unless tpath.start_with?(path)
61
+ next unless HTTP::Cookie.path_match?(path, tpath)
60
62
  hash.delete_if { |name, cookie|
61
63
  if cookie.expired?
62
64
  true
@@ -19,15 +19,3 @@ module Enumerable
19
19
  result
20
20
  end
21
21
  end
22
-
23
- module Test::Unit::Assertions
24
- def assert_raises_with_message(exc, re, message = nil, &block)
25
- e = nil
26
- begin
27
- block.call
28
- rescue Exception => e
29
- end
30
- assert_instance_of(exc, e, message)
31
- assert_match(re, e.message, message)
32
- end
33
- end
@@ -502,9 +502,10 @@ class TestHTTPCookie < Test::Unit::TestCase
502
502
  { :created_at => time },
503
503
  { :created_at => time, :path => '/foo/bar/' },
504
504
  { :created_at => time, :path => '/foo/' },
505
+ { :created_at => time, :path => '/foo' },
505
506
  ].map { |attrs| HTTP::Cookie.new(cookie_values(attrs)) }
506
507
 
507
- assert_equal([3, 4, 1, 2, 0], cookies.sort.map { |i|
508
+ assert_equal([3, 4, 5, 1, 2, 0], cookies.sort.map { |i|
508
509
  cookies.find_index { |j| j.equal?(i) }
509
510
  })
510
511
  end
@@ -576,6 +577,32 @@ class TestHTTPCookie < Test::Unit::TestCase
576
577
  }
577
578
  end
578
579
 
580
+ def test_path
581
+ uri = URI.parse('http://example.com/foo/bar')
582
+
583
+ assert_equal '/foo/bar', uri.path
584
+
585
+ cookie_str = 'a=b'
586
+ cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
587
+ assert '/foo/', cookie.path
588
+
589
+ cookie_str = 'a=b; path=/foo'
590
+ cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
591
+ assert '/foo', cookie.path
592
+
593
+ uri = URI.parse('http://example.com')
594
+
595
+ assert_equal '', uri.path
596
+
597
+ cookie_str = 'a=b'
598
+ cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
599
+ assert '/', cookie.path
600
+
601
+ cookie_str = 'a=b; path=/foo'
602
+ cookie = HTTP::Cookie.parse(cookie_str, :origin => uri).first
603
+ assert '/foo', cookie.path
604
+ end
605
+
579
606
  def test_domain_nil
580
607
  cookie = HTTP::Cookie.parse('a=b').first
581
608
  assert_raises(RuntimeError) {
@@ -635,63 +662,126 @@ class TestHTTPCookie < Test::Unit::TestCase
635
662
  end
636
663
 
637
664
  def test_valid_for_uri?
638
- cookie = HTTP::Cookie.parse('a=b', :origin => URI('http://example.com/dir/file.html')).first
639
- assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
640
- assert_equal true, cookie.valid_for_uri?('https://example.com/dir/test.html')
641
- assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
642
- assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
643
- assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
644
- assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html'))
645
- assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
646
- assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
647
- assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
648
- assert_equal false, cookie.valid_for_uri?(URI('file:///dir/test.html'))
649
-
650
- cookie = HTTP::Cookie.parse('a=b; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first
651
- assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
652
- assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
653
- assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
654
- assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
655
- assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html'))
656
- assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
657
- assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
658
- assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
659
- assert_equal false, cookie.valid_for_uri?(URI('file:///dir/test.html'))
660
-
661
- cookie = HTTP::Cookie.parse('a=b; domain=example.com; path=/dir2/', :origin => URI('http://example.com/dir/file.html')).first
662
- assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
663
- assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
664
- assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
665
- assert_equal true, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
666
- assert_equal false, cookie.valid_for_uri?(URI('https://www.example.com/dir/test.html'))
667
- assert_equal false, cookie.valid_for_uri?(URI('http://www.example.com/dir/test.html'))
668
- assert_equal true, cookie.valid_for_uri?(URI('https://www.example.com/dir2/test.html'))
669
- assert_equal true, cookie.valid_for_uri?(URI('http://www.example.com/dir2/test.html'))
670
- assert_equal false, cookie.valid_for_uri?(URI('file:///dir2/test.html'))
671
-
672
- cookie = HTTP::Cookie.parse('a=b; secure', :origin => URI('https://example.com/dir/file.html')).first
673
- assert_equal true, cookie.valid_for_uri?(URI('https://example.com/dir/test.html'))
674
- assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir/test.html'))
675
- assert_equal false, cookie.valid_for_uri?(URI('https://example.com/dir2/test.html'))
676
- assert_equal false, cookie.valid_for_uri?(URI('http://example.com/dir2/test.html'))
677
- assert_equal false, cookie.valid_for_uri?(URI('file:///dir2/test.html'))
678
-
679
- cookie = HTTP::Cookie.parse('a=b', :origin => URI('https://example.com/')).first
680
- assert_equal true, cookie.valid_for_uri?(URI('https://example.com'))
681
- assert_equal false, cookie.valid_for_uri?(URI('file:///'))
682
- end
683
-
684
- def test_migration
685
- assert_raises_with_message(ArgumentError, /equivalent/) {
686
- HTTP::Cookie.parse('http://example.com/', 'key=value')
687
- }
688
- assert_raises_with_message(ArgumentError, /equivalent/) {
689
- HTTP::Cookie.parse('http://example.com/', 'key=value', Object.new)
665
+ {
666
+ HTTP::Cookie.parse('a1=b',
667
+ :origin => 'http://example.com/dir/file.html').first => {
668
+ true => [
669
+ 'http://example.com/dir/',
670
+ 'http://example.com/dir/test.html',
671
+ 'https://example.com/dir/',
672
+ 'https://example.com/dir/test.html',
673
+ ],
674
+ false => [
675
+ 'file:///dir/test.html',
676
+ 'http://example.com/dir',
677
+ 'http://example.com/dir2/test.html',
678
+ 'http://www.example.com/dir/test.html',
679
+ 'http://www.example.com/dir2/test.html',
680
+ 'https://example.com/dir',
681
+ 'https://example.com/dir2/test.html',
682
+ 'https://www.example.com/dir/test.html',
683
+ 'https://www.example.com/dir2/test.html',
684
+ ]
685
+ },
686
+ HTTP::Cookie.parse('a2=b; path=/dir2/',
687
+ :origin => 'http://example.com/dir/file.html').first => {
688
+ true => [
689
+ 'http://example.com/dir2/',
690
+ 'http://example.com/dir2/test.html',
691
+ 'https://example.com/dir2/',
692
+ 'https://example.com/dir2/test.html',
693
+ ],
694
+ false => [
695
+ 'file:///dir/test.html',
696
+ 'http://example.com/dir/test.html',
697
+ 'http://www.example.com/dir/test.html',
698
+ 'http://www.example.com/dir2',
699
+ 'http://www.example.com/dir2/test.html',
700
+ 'https://example.com/dir/test.html',
701
+ 'https://www.example.com/dir/test.html',
702
+ 'https://www.example.com/dir2',
703
+ 'https://www.example.com/dir2/test.html',
704
+ ]
705
+ },
706
+ HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2/',
707
+ :origin => URI('http://example.com/dir/file.html')).first => {
708
+ true => [
709
+ 'https://example.com/dir2/test.html',
710
+ 'http://example.com/dir2/test.html',
711
+ 'https://www.example.com/dir2/test.html',
712
+ 'http://www.example.com/dir2/test.html',
713
+ ],
714
+ false => [
715
+ 'https://example.com/dir/test.html',
716
+ 'http://example.com/dir/test.html',
717
+ 'https://www.example.com/dir/test.html',
718
+ 'http://www.example.com/dir/test.html',
719
+ 'file:///dir2/test.html',
720
+ ]
721
+ },
722
+ HTTP::Cookie.parse('a4=b; secure',
723
+ :origin => URI('https://example.com/dir/file.html')).first => {
724
+ true => [
725
+ 'https://example.com/dir/test.html',
726
+ ],
727
+ false => [
728
+ 'http://example.com/dir/test.html',
729
+ 'https://example.com/dir2/test.html',
730
+ 'http://example.com/dir2/test.html',
731
+ 'file:///dir2/test.html',
732
+ ]
733
+ },
734
+ HTTP::Cookie.parse('a5=b',
735
+ :origin => URI('https://example.com/')).first => {
736
+ true => [
737
+ 'https://example.com',
738
+ ],
739
+ false => [
740
+ 'file:///',
741
+ ]
742
+ },
743
+ HTTP::Cookie.parse('a6=b; path=/dir',
744
+ :origin => 'http://example.com/dir/file.html').first => {
745
+ true => [
746
+ 'http://example.com/dir',
747
+ 'http://example.com/dir/',
748
+ 'http://example.com/dir/test.html',
749
+ 'https://example.com/dir',
750
+ 'https://example.com/dir/',
751
+ 'https://example.com/dir/test.html',
752
+ ],
753
+ false => [
754
+ 'file:///dir/test.html',
755
+ 'http://example.com/dir2',
756
+ 'http://example.com/dir2/test.html',
757
+ 'http://www.example.com/dir/test.html',
758
+ 'http://www.example.com/dir2/test.html',
759
+ 'https://example.com/dir2',
760
+ 'https://example.com/dir2/test.html',
761
+ 'https://www.example.com/dir/test.html',
762
+ 'https://www.example.com/dir2/test.html',
763
+ ]
764
+ },
765
+ }.each { |cookie, hash|
766
+ hash.each { |expected, urls|
767
+ urls.each { |url|
768
+ assert_equal expected, cookie.valid_for_uri?(url), '%s: %s' % [cookie.name, url]
769
+ assert_equal expected, cookie.valid_for_uri?(URI(url)), "%s: URI(%s)" % [cookie.name, url]
770
+ }
771
+ }
690
772
  }
773
+ end
691
774
 
692
- cookie = HTTP::Cookie.new('key', 'value')
693
- assert_raises_with_message(NoMethodError, /equivalent/) {
694
- cookie.set_domain('www.example.com')
695
- }
775
+ def test_s_path_match?
776
+ assert_equal true, HTTP::Cookie.path_match?('/admin/', '/admin/index')
777
+ assert_equal false, HTTP::Cookie.path_match?('/admin/', '/Admin/index')
778
+ assert_equal true, HTTP::Cookie.path_match?('/admin/', '/admin/')
779
+ assert_equal false, HTTP::Cookie.path_match?('/admin/', '/admin')
780
+
781
+ assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin')
782
+ assert_equal false, HTTP::Cookie.path_match?('/admin', '/Admin')
783
+ assert_equal false, HTTP::Cookie.path_match?('/admin', '/admins')
784
+ assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin/')
785
+ assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin/index')
696
786
  end
697
787
  end
@@ -569,20 +569,4 @@ class TestHTTPCookieJar < Test::Unit::TestCase
569
569
  cookie.domain == cookie.value
570
570
  }
571
571
  end
572
-
573
- def test_migration
574
- cookie = HTTP::Cookie.new(cookie_values)
575
- assert_raises_with_message(ArgumentError, /equivalent/) {
576
- @jar.add('http://example.com/', cookie)
577
- }
578
- assert_raises_with_message(NoMethodError, /equivalent/) {
579
- @jar.add!(cookie)
580
- }
581
- assert_raises_with_message(NoMethodError, /equivalent/) {
582
- @jar.clear!()
583
- }
584
- assert_raises_with_message(NoMethodError, /equivalent/) {
585
- @jar.save_as('/dev/null')
586
- }
587
- end
588
572
  end
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.0.pre1
4
+ version: 1.0.0.pre2
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: 2013-03-21 00:00:00.000000000 Z
14
+ date: 2013-03-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: domain_name
@@ -105,7 +105,9 @@ email:
105
105
  - mike.dalessio@gmail.com
106
106
  executables: []
107
107
  extensions: []
108
- extra_rdoc_files: []
108
+ extra_rdoc_files:
109
+ - README.md
110
+ - LICENSE.txt
109
111
  files:
110
112
  - .gitignore
111
113
  - .travis.yml