public-suffix-list 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4006daada672cf9894459ab481c57db88766bc0e72a5a387d60eff7e5731b155
4
+ data.tar.gz: 7b30374afa59207f4c71a58454af749f07b0b59b07a01e17d828bd00689e06f4
5
+ SHA512:
6
+ metadata.gz: 52ea05bd99cfee402a61c0d8f05a8080a53ada2e8842d5ad739effbc5b181093cf5f076223982a1480efe9d044dfefc51b4ee06e51cdb229c5b048dff429329a
7
+ data.tar.gz: 54366755a919b771e77709af783e4bf2c436d76eddccf00eb9796bc59d9069b35775362f0c5b56ee91e8f921f40af7163fe097906d72594ee25205c57cdeee16
@@ -75,7 +75,7 @@ Or add it to your Gemfile and use bundler:
75
75
 
76
76
  == License
77
77
 
78
- Copyright (c) 2010-2017 Todd Sundsted
78
+ Copyright (c) 2010-2019 Todd Sundsted
79
79
 
80
80
  Permission is hereby granted, free of charge, to any person obtaining
81
81
  a copy of this software and associated documentation files (the
@@ -6,7 +6,7 @@ require "public_suffix_list/parser.rb"
6
6
 
7
7
  class PublicSuffixList
8
8
 
9
- VERSION = "0.1.6"
9
+ VERSION = "0.2.0"
10
10
 
11
11
  def self.config
12
12
  @@config ||= Config.new
@@ -29,7 +29,7 @@ class PublicSuffixList
29
29
  def initialize
30
30
  @cache_dir = nil
31
31
  @cache_expiry_period = 30 * 24 * 60 * 60
32
- @url = "https://publicsuffix.org/list/effective_tld_names.dat"
32
+ @url = "https://publicsuffix.org/list/public_suffix_list.dat"
33
33
  end
34
34
 
35
35
  end
@@ -57,19 +57,19 @@ class PublicSuffixList
57
57
 
58
58
  def split(domain)
59
59
  domain = domain.split(".")
60
- result = best(match(domain, rules))
60
+ result = best(match(domain, rules, true))
61
61
  [gimme!(domain, result.size), gimme!(domain), domain].reverse.map { |d| d ? d.join(".") : "" }
62
62
  end
63
63
 
64
64
  def tld(domain)
65
65
  domain = domain.split(".")
66
- result = best(match(domain, rules))
66
+ result = best(match(domain, rules, true))
67
67
  gimme!(domain, result.size).join(".")
68
68
  end
69
69
 
70
70
  def cdn(domain)
71
71
  domain = domain.split(".")
72
- result = best(match(domain, rules))
72
+ result = best(match(domain, rules, true))
73
73
  gimme!(domain, result.size + 1).join(".")
74
74
  end
75
75
 
@@ -87,7 +87,7 @@ class PublicSuffixList
87
87
  @rules = @cache_file[:rules] unless @cache_file.expired?
88
88
  end
89
89
 
90
- def match(domain, rules)
90
+ def match(domain, rules, wildcard = false)
91
91
  return [] if domain.empty? or rules.empty?
92
92
  domain = domain.dup
93
93
  first = domain.pop
@@ -96,8 +96,12 @@ class PublicSuffixList
96
96
  if rules[pattern]
97
97
  set << [name] if rules[pattern][:term]
98
98
  match(domain, rules[pattern]).each { |result| set << [first] + result }
99
+ wildcard = false
99
100
  end
100
101
  end
102
+ if wildcard
103
+ set << [domain.first]
104
+ end
101
105
  set
102
106
  end
103
107
 
@@ -10,7 +10,7 @@ class PublicSuffixList
10
10
  # !metro.tokyo.jp
11
11
 
12
12
  # {
13
- # "com" => {:term => true},
13
+ # "com" => {:term => true},
14
14
  # "jp" => {
15
15
  # "tokyo" => {"!metro" => {:term => true}, "*" => {:term => true}},
16
16
  # "hokkaido" => {"!pref" => {:term => true}, "*" => {:term => true}},
@@ -20,10 +20,10 @@ class PublicSuffixList
20
20
 
21
21
  def self.parse(lines)
22
22
  lines.inject({}) do |acc, line|
23
- line.strip!
23
+ line.gsub!(/\s.*/, "")
24
24
  unless line =~ %r{//} or line.empty?
25
25
  tmp = acc
26
- line.split(".").reverse.each do |p|
26
+ line.split(".").reject(&:empty?).reverse.each do |p|
27
27
  tmp[p] = {} unless tmp[p]
28
28
  tmp = tmp[p]
29
29
  end
@@ -12,12 +12,12 @@ describe PublicSuffixList do
12
12
 
13
13
  it "should cache when instructed to do so" do
14
14
  File.exist?(FILE).should be false
15
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
15
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
16
16
  public_suffix_list.cache_file.cache?.should be true
17
17
  public_suffix_list.cache_file.exist?.should be true
18
18
  created_at = public_suffix_list.cache_file.data[:created_at]
19
19
  tag = public_suffix_list.cache_file.data[:tag]
20
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
20
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
21
21
  public_suffix_list.cache_file.cache?.should be true
22
22
  public_suffix_list.cache_file.exist?.should be true
23
23
  public_suffix_list.cache_file.data[:created_at].should == created_at
@@ -26,13 +26,13 @@ describe PublicSuffixList do
26
26
 
27
27
  it "should fetch a new data file when the cache expiry has passed" do
28
28
  File.exist?(FILE).should be false
29
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
29
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
30
30
  public_suffix_list.cache_file.cache?.should be true
31
31
  public_suffix_list.cache_file.exist?.should be true
32
32
  created_at = public_suffix_list.cache_file.data[:created_at]
33
33
  tag = public_suffix_list.cache_file.data[:tag]
34
34
  Timecop.travel(Time.now + 15) do
35
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
35
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
36
36
  public_suffix_list.cache_file.cache?.should be true
37
37
  public_suffix_list.cache_file.exist?.should be true
38
38
  public_suffix_list.cache_file.data[:created_at].should_not == created_at
@@ -42,13 +42,13 @@ describe PublicSuffixList do
42
42
 
43
43
  it "should not fetch a new data file when the cache expiry has not passed" do
44
44
  File.exist?(FILE).should be false
45
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
45
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
46
46
  public_suffix_list.cache_file.cache?.should be true
47
47
  public_suffix_list.cache_file.exist?.should be true
48
48
  created_at = public_suffix_list.cache_file.data[:created_at]
49
49
  tag = public_suffix_list.cache_file.data[:tag]
50
50
  Timecop.travel(Time.now + 5) do
51
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
51
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
52
52
  public_suffix_list.cache_file.cache?.should be true
53
53
  public_suffix_list.cache_file.exist?.should be true
54
54
  public_suffix_list.cache_file.data[:created_at].should == created_at
@@ -58,7 +58,7 @@ describe PublicSuffixList do
58
58
 
59
59
  it "should allow 0 or nil to specify an infinite cache expiry period" do
60
60
  File.exist?(FILE).should be false
61
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
61
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 10)
62
62
  public_suffix_list.cache_file.exist?.should be true
63
63
  public_suffix_list.cache_file.expired?.should be false
64
64
  public_suffix_list.cache_file.data[:created_at] = Time.now - 100
@@ -66,7 +66,7 @@ describe PublicSuffixList do
66
66
  public_suffix_list.cache_file.exist?.should be true
67
67
  public_suffix_list.cache_file.delete
68
68
  public_suffix_list.cache_file.exist?.should be false
69
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 0)
69
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => 0)
70
70
  public_suffix_list.cache_file.exist?.should be true
71
71
  public_suffix_list.cache_file.expired?.should be false
72
72
  public_suffix_list.cache_file.data[:created_at] = Time.now - 10000000
@@ -74,7 +74,7 @@ describe PublicSuffixList do
74
74
  public_suffix_list.cache_file.exist?.should be true
75
75
  public_suffix_list.cache_file.delete
76
76
  public_suffix_list.cache_file.exist?.should be false
77
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => nil)
77
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat", :cache_dir => Dir.tmpdir, :cache_expiry_period => nil)
78
78
  public_suffix_list.cache_file.exist?.should be true
79
79
  public_suffix_list.cache_file.expired?.should be false
80
80
  public_suffix_list.cache_file.data[:created_at] = Time.now - 10000000
@@ -8,7 +8,7 @@ end
8
8
  describe PublicSuffixList do
9
9
 
10
10
  it "should calculate cookies as described at http://publicsuffix.org/format/" do
11
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
11
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
12
12
  cookie_calculation(public_suffix_list, "foo.com").should == "Cookies may be set for foo.com."
13
13
  cookie_calculation(public_suffix_list, "foo.bar.jp").should == "Cookies may be set for foo.bar.jp."
14
14
  cookie_calculation(public_suffix_list, "bar.jp").should == "Cookies may not be set for bar.jp."
@@ -2,17 +2,16 @@ require 'public_suffix_list'
2
2
 
3
3
  describe PublicSuffixList do
4
4
 
5
- it "should accept both effective_tld_names_url and url" do
6
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
7
- public_suffix_list.config.effective_tld_names_url.should == "spec/test.dat"
8
- public_suffix_list.config.url.should == "spec/test.dat"
5
+ it "should match * if no rules match" do
9
6
  public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
10
- public_suffix_list.config.effective_tld_names_url.should == "spec/test.dat"
11
- public_suffix_list.config.url.should == "spec/test.dat"
7
+ public_suffix_list.cache_file.should be nil
8
+ public_suffix_list.split("www.home.foobar").should == ["www", "home", "foobar"]
9
+ public_suffix_list.cdn("www.home.foobar").should == "home.foobar"
10
+ public_suffix_list.tld("www.home.foobar").should == "foobar"
12
11
  end
13
12
 
14
13
  it "should calculate tld and cdn correctly" do
15
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
14
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
16
15
  public_suffix_list.cache_file.should be nil
17
16
  public_suffix_list.cdn("foo.bar.com").should == "bar.com"
18
17
  public_suffix_list.tld("foo.bar.com").should == "com"
@@ -21,7 +20,7 @@ describe PublicSuffixList do
21
20
  end
22
21
 
23
22
  it "should not assume the root name is a top level domain" do
24
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
23
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
25
24
  public_suffix_list.cache_file.should be nil
26
25
  public_suffix_list.tld("com").should == "com"
27
26
  public_suffix_list.tld("bar.foo").should == "bar.foo"
@@ -31,7 +30,7 @@ describe PublicSuffixList do
31
30
  end
32
31
 
33
32
  it "should handle edge cases correctly" do
34
- public_suffix_list = PublicSuffixList.new(:effective_tld_names_url => "spec/test.dat")
33
+ public_suffix_list = PublicSuffixList.new(:url => "spec/test.dat")
35
34
  public_suffix_list.cache_file.should be nil
36
35
  public_suffix_list.split("").should == ["", "", ""]
37
36
  public_suffix_list.cdn("").should == ""
@@ -4,7 +4,7 @@ com
4
4
  *.hokkaido.jp
5
5
  *.tokyo.jp
6
6
  !pref.hokkaido.jp
7
- !metro.tokyo.jp
7
+ !metro.tokyo.jp
8
8
 
9
9
  // "foo" and "qux.foo" are not tlds
10
10
  bar.foo
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public-suffix-list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Todd Sundsted
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2017-06-15 00:00:00.000000000 Z
11
+ date: 2019-04-04 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: The Public Suffix List (http://publicsuffix.org/) is "a cross-vendor
15
14
  initiative to provide an accurate list of domain name suffixes". Such a list is
@@ -28,35 +27,34 @@ files:
28
27
  - lib/public_suffix_list.rb
29
28
  - lib/public_suffix_list/cache_file.rb
30
29
  - lib/public_suffix_list/parser.rb
31
- - spec/caching.spec
32
- - spec/cookie_calculation.spec
33
- - spec/public_suffix_list.spec
34
- - spec/rdoc_synopsis.spec
35
- - spec/upcase_downcase.spec
30
+ - spec/caching_spec.rb
31
+ - spec/cookie_calculation_spec.rb
32
+ - spec/public_suffix_list_spec.rb
33
+ - spec/rdoc_synopsis_spec.rb
36
34
  - spec/test.dat
35
+ - spec/upcase_downcase_spec.rb
37
36
  homepage: http://github.com/toddsundsted/Public-Suffix-List
38
37
  licenses: []
38
+ metadata: {}
39
39
  post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
43
43
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
44
  requirements:
46
- - - ! '>='
45
+ - - ">="
47
46
  - !ruby/object:Gem::Version
48
47
  version: '0'
49
48
  required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
49
  requirements:
52
- - - ! '>='
50
+ - - ">="
53
51
  - !ruby/object:Gem::Version
54
52
  version: '0'
55
53
  requirements: []
56
54
  rubyforge_project:
57
- rubygems_version: 1.8.23
55
+ rubygems_version: 2.7.6
58
56
  signing_key:
59
- specification_version: 3
57
+ specification_version: 4
60
58
  summary: Public Suffix List is a small Ruby library designed to make the Public Suffix
61
59
  List (http://publicsuffix.org/) easier to use.
62
60
  test_files: []