public_suffix 2.0.5 → 3.0.0

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.
@@ -6,5 +6,5 @@
6
6
 
7
7
  module PublicSuffix
8
8
  # The current library version.
9
- VERSION = "2.0.5".freeze
9
+ VERSION = "3.0.0".freeze
10
10
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = "PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains."
13
13
  s.licenses = ["MIT"]
14
14
 
15
- s.required_ruby_version = ">= 2.0"
15
+ s.required_ruby_version = ">= 2.1"
16
16
 
17
17
  s.require_paths = ["lib"]
18
18
  s.files = `git ls-files`.split("\n")
@@ -0,0 +1,2 @@
1
+ # This is an empty file I use to force a non-empty commit when I only need to store notes
2
+ ..
@@ -19,7 +19,11 @@ class AcceptanceTest < Minitest::Test
19
19
  trd, sld, tld = results
20
20
  assert_equal tld, parsed.tld, "Invalid tld for `#{name}`"
21
21
  assert_equal sld, parsed.sld, "Invalid sld for `#{name}`"
22
- assert_equal trd, parsed.trd, "Invalid trd for `#{name}`"
22
+ if trd.nil?
23
+ assert_nil parsed.trd, "Invalid trd for `#{name}`"
24
+ else
25
+ assert_equal trd, parsed.trd, "Invalid trd for `#{name}`"
26
+ end
23
27
 
24
28
  assert_equal domain, PublicSuffix.domain(input)
25
29
  assert PublicSuffix.valid?(input)
@@ -93,7 +97,11 @@ class AcceptanceTest < Minitest::Test
93
97
  def test_ignore_private
94
98
  # test domain and parse
95
99
  INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
96
- assert_equal expected, PublicSuffix.domain(given, ignore_private: ignore_private)
100
+ if expected.nil?
101
+ assert_nil PublicSuffix.domain(given, ignore_private: ignore_private)
102
+ else
103
+ assert_equal expected, PublicSuffix.domain(given, ignore_private: ignore_private)
104
+ end
97
105
  end
98
106
  # test valid?
99
107
  INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
@@ -0,0 +1,66 @@
1
+ require 'benchmark'
2
+ require_relative "../../lib/public_suffix"
3
+
4
+ NAME_SHORT = "example.de"
5
+ NAME_MEDIUM = "www.subdomain.example.de"
6
+ NAME_LONG = "one.two.three.four.five.example.de"
7
+ NAME_WILD = "one.two.three.four.five.example.bd"
8
+ NAME_EXCP = "one.two.three.four.five.www.ck"
9
+
10
+ IAAA = "www.example.ac"
11
+ IZZZ = "www.example.zone"
12
+
13
+ PAAA = "one.two.three.four.five.example.beep.pl"
14
+ PZZZ = "one.two.three.four.five.example.now.sh"
15
+
16
+ JP = "www.yokoshibahikari.chiba.jp"
17
+ IT = "www.example.it"
18
+ COM = "www.example.com"
19
+
20
+ TIMES = (ARGV.first || 50_000).to_i
21
+
22
+ # Initialize
23
+ PublicSuffixList = PublicSuffix::List.default
24
+ PublicSuffixList.find("example.com")
25
+
26
+ Benchmark.bmbm(25) do |x|
27
+ x.report("NAME_SHORT") do
28
+ TIMES.times { PublicSuffixList.find(NAME_SHORT) != nil }
29
+ end
30
+ x.report("NAME_MEDIUM") do
31
+ TIMES.times { PublicSuffixList.find(NAME_MEDIUM) != nil }
32
+ end
33
+ x.report("NAME_LONG") do
34
+ TIMES.times { PublicSuffixList.find(NAME_LONG) != nil }
35
+ end
36
+ x.report("NAME_WILD") do
37
+ TIMES.times { PublicSuffixList.find(NAME_WILD) != nil }
38
+ end
39
+ x.report("NAME_EXCP") do
40
+ TIMES.times { PublicSuffixList.find(NAME_EXCP) != nil }
41
+ end
42
+
43
+ x.report("IAAA") do
44
+ TIMES.times { PublicSuffixList.find(IAAA) != nil }
45
+ end
46
+ x.report("IZZZ") do
47
+ TIMES.times { PublicSuffixList.find(IZZZ) != nil }
48
+ end
49
+
50
+ x.report("PAAA") do
51
+ TIMES.times { PublicSuffixList.find(PAAA) != nil }
52
+ end
53
+ x.report("PZZZ") do
54
+ TIMES.times { PublicSuffixList.find(PZZZ) != nil }
55
+ end
56
+
57
+ x.report("JP") do
58
+ TIMES.times { PublicSuffixList.find(JP) != nil }
59
+ end
60
+ x.report("IT") do
61
+ TIMES.times { PublicSuffixList.find(IT) != nil }
62
+ end
63
+ x.report("COM") do
64
+ TIMES.times { PublicSuffixList.find(COM) != nil }
65
+ end
66
+ end
@@ -0,0 +1,102 @@
1
+ require 'benchmark'
2
+ require_relative "../../lib/public_suffix"
3
+
4
+ NAME_SHORT = "example.de"
5
+ NAME_MEDIUM = "www.subdomain.example.de"
6
+ NAME_LONG = "one.two.three.four.five.example.de"
7
+ NAME_WILD = "one.two.three.four.five.example.bd"
8
+ NAME_EXCP = "one.two.three.four.five.www.ck"
9
+
10
+ IAAA = "www.example.ac"
11
+ IZZZ = "www.example.zone"
12
+
13
+ PAAA = "one.two.three.four.five.example.beep.pl"
14
+ PZZZ = "one.two.three.four.five.example.now.sh"
15
+
16
+ JP = "www.yokoshibahikari.chiba.jp"
17
+ IT = "www.example.it"
18
+ COM = "www.example.com"
19
+
20
+ TIMES = (ARGV.first || 50_000).to_i
21
+
22
+ # Initialize
23
+ PublicSuffixList = PublicSuffix::List.default
24
+ PublicSuffixList.find("example.com")
25
+
26
+ Benchmark.bmbm(25) do |x|
27
+ x.report("NAME_SHORT") do
28
+ TIMES.times { PublicSuffixList.find(NAME_SHORT) != nil }
29
+ end
30
+ x.report("NAME_SHORT (noprivate)") do
31
+ TIMES.times { PublicSuffixList.find(NAME_SHORT, ignore_private: true) != nil }
32
+ end
33
+ x.report("NAME_MEDIUM") do
34
+ TIMES.times { PublicSuffixList.find(NAME_MEDIUM) != nil }
35
+ end
36
+ x.report("NAME_MEDIUM (noprivate)") do
37
+ TIMES.times { PublicSuffixList.find(NAME_MEDIUM, ignore_private: true) != nil }
38
+ end
39
+ x.report("NAME_LONG") do
40
+ TIMES.times { PublicSuffixList.find(NAME_LONG) != nil }
41
+ end
42
+ x.report("NAME_LONG (noprivate)") do
43
+ TIMES.times { PublicSuffixList.find(NAME_LONG, ignore_private: true) != nil }
44
+ end
45
+ x.report("NAME_WILD") do
46
+ TIMES.times { PublicSuffixList.find(NAME_WILD) != nil }
47
+ end
48
+ x.report("NAME_WILD (noprivate)") do
49
+ TIMES.times { PublicSuffixList.find(NAME_WILD, ignore_private: true) != nil }
50
+ end
51
+ x.report("NAME_EXCP") do
52
+ TIMES.times { PublicSuffixList.find(NAME_EXCP) != nil }
53
+ end
54
+ x.report("NAME_EXCP (noprivate)") do
55
+ TIMES.times { PublicSuffixList.find(NAME_EXCP, ignore_private: true) != nil }
56
+ end
57
+
58
+ x.report("IAAA") do
59
+ TIMES.times { PublicSuffixList.find(IAAA) != nil }
60
+ end
61
+ x.report("IAAA (noprivate)") do
62
+ TIMES.times { PublicSuffixList.find(IAAA, ignore_private: true) != nil }
63
+ end
64
+ x.report("IZZZ") do
65
+ TIMES.times { PublicSuffixList.find(IZZZ) != nil }
66
+ end
67
+ x.report("IZZZ (noprivate)") do
68
+ TIMES.times { PublicSuffixList.find(IZZZ, ignore_private: true) != nil }
69
+ end
70
+
71
+ x.report("PAAA") do
72
+ TIMES.times { PublicSuffixList.find(PAAA) != nil }
73
+ end
74
+ x.report("PAAA (noprivate)") do
75
+ TIMES.times { PublicSuffixList.find(PAAA, ignore_private: true) != nil }
76
+ end
77
+ x.report("PZZZ") do
78
+ TIMES.times { PublicSuffixList.find(PZZZ) != nil }
79
+ end
80
+ x.report("PZZZ (noprivate)") do
81
+ TIMES.times { PublicSuffixList.find(PZZZ, ignore_private: true) != nil }
82
+ end
83
+
84
+ x.report("JP") do
85
+ TIMES.times { PublicSuffixList.find(JP) != nil }
86
+ end
87
+ x.report("JP (noprivate)") do
88
+ TIMES.times { PublicSuffixList.find(JP, ignore_private: true) != nil }
89
+ end
90
+ x.report("IT") do
91
+ TIMES.times { PublicSuffixList.find(IT) != nil }
92
+ end
93
+ x.report("IT (noprivate)") do
94
+ TIMES.times { PublicSuffixList.find(IT, ignore_private: true) != nil }
95
+ end
96
+ x.report("COM") do
97
+ TIMES.times { PublicSuffixList.find(COM) != nil }
98
+ end
99
+ x.report("COM (noprivate)") do
100
+ TIMES.times { PublicSuffixList.find(COM, ignore_private: true) != nil }
101
+ end
102
+ end
@@ -0,0 +1,91 @@
1
+ require 'benchmark/ips'
2
+
3
+ STRING = "www.subdomain.example.com"
4
+ ARRAY = %w(
5
+ com
6
+ example.com
7
+ subdomain.example.com
8
+ www.subdomain.example.com
9
+ )
10
+
11
+ def tokenizer1(string)
12
+ parts = string.split(".").reverse!
13
+ index = 0
14
+ query = parts[index]
15
+ names = []
16
+
17
+ loop do
18
+ names << query
19
+
20
+ index += 1
21
+ break if index >= parts.size
22
+ query = parts[index] + "." + query
23
+ end
24
+ names
25
+ end
26
+
27
+ def tokenizer2(string)
28
+ parts = string.split(".")
29
+ index = parts.size - 1
30
+ query = parts[index]
31
+ names = []
32
+
33
+ loop do
34
+ names << query
35
+
36
+ index -= 1
37
+ break if index < 0
38
+ query = parts[index] + "." + query
39
+ end
40
+ names
41
+ end
42
+
43
+ def tokenizer3(string)
44
+ isx = string.size
45
+ idx = string.size - 1
46
+ names = []
47
+
48
+ loop do
49
+ isx = string.rindex(".", isx - 1) || -1
50
+ names << string[isx + 1, idx - isx]
51
+
52
+ break if isx <= 0
53
+ end
54
+ names
55
+ end
56
+
57
+ def tokenizer4(string)
58
+ isx = string.size
59
+ idx = string.size - 1
60
+ names = []
61
+
62
+ loop do
63
+ isx = string.rindex(".", isx - 1) || -1
64
+ names << string[(isx+1)..idx]
65
+
66
+ break if isx <= 0
67
+ end
68
+ names
69
+ end
70
+
71
+ (x = tokenizer1(STRING)) == ARRAY or fail("tokenizer1 failed: #{x.inspect}")
72
+ (x = tokenizer2(STRING)) == ARRAY or fail("tokenizer2 failed: #{x.inspect}")
73
+ (x = tokenizer3(STRING)) == ARRAY or fail("tokenizer3 failed: #{x.inspect}")
74
+ (x = tokenizer4(STRING)) == ARRAY or fail("tokenizer4 failed: #{x.inspect}")
75
+
76
+ Benchmark.ips do |x|
77
+ x.report("tokenizer1") do
78
+ tokenizer1(STRING).is_a?(Array)
79
+ end
80
+ x.report("tokenizer2") do
81
+ tokenizer2(STRING).is_a?(Array)
82
+ end
83
+ x.report("tokenizer3") do
84
+ tokenizer3(STRING).is_a?(Array)
85
+ end
86
+ x.report("tokenizer4") do
87
+ tokenizer4(STRING).is_a?(Array)
88
+ end
89
+
90
+ x.compare!
91
+ end
@@ -0,0 +1,26 @@
1
+ require 'benchmark'
2
+ require_relative "../../lib/public_suffix"
3
+
4
+ JP = "www.yokoshibahikari.chiba.jp"
5
+
6
+ TIMES = (ARGV.first || 50_000).to_i
7
+
8
+ # Initialize
9
+ class PublicSuffix::List
10
+ public :select
11
+ end
12
+ PublicSuffixList = PublicSuffix::List.default
13
+ PublicSuffixList.select("example.jp")
14
+ PublicSuffixList.find("example.jp")
15
+
16
+ Benchmark.bmbm(25) do |x|
17
+ x.report("JP select") do
18
+ TIMES.times { PublicSuffixList.select(JP) }
19
+ end
20
+ x.report("JP find") do
21
+ TIMES.times { PublicSuffixList.find(JP) }
22
+ end
23
+ # x.report("JP (noprivate)") do
24
+ # TIMES.times { PublicSuffixList.find(JP, ignore_private: true) != nil }
25
+ # end
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'benchmark'
2
+ require_relative "../../lib/public_suffix"
3
+
4
+ JP = "www.yokoshibahikari.chiba.jp"
5
+
6
+ TIMES = (ARGV.first || 50_000).to_i
7
+
8
+ # Initialize
9
+ class PublicSuffix::List
10
+ public :select
11
+ end
12
+ PublicSuffixList = PublicSuffix::List.default
13
+ PublicSuffixList.select("example.jp")
14
+
15
+ Benchmark.bmbm(25) do |x|
16
+ x.report("select jp") do
17
+ TIMES.times { PublicSuffixList.select("jp") }
18
+ end
19
+ x.report("select example.jp") do
20
+ TIMES.times { PublicSuffixList.select("example.jp") }
21
+ end
22
+ x.report("select www.example.jp") do
23
+ TIMES.times { PublicSuffixList.select("www.example.jp") }
24
+ end
25
+ end
@@ -0,0 +1,101 @@
1
+ require 'benchmark'
2
+ require_relative "../../lib/public_suffix"
3
+
4
+ NAME_SHORT = "example.de"
5
+ NAME_MEDIUM = "www.subdomain.example.de"
6
+ NAME_LONG = "one.two.three.four.five.example.de"
7
+ NAME_WILD = "one.two.three.four.five.example.bd"
8
+ NAME_EXCP = "one.two.three.four.five.www.ck"
9
+
10
+ IAAA = "www.example.ac"
11
+ IZZZ = "www.example.zone"
12
+
13
+ PAAA = "one.two.three.four.five.example.beep.pl"
14
+ PZZZ = "one.two.three.four.five.example.now.sh"
15
+
16
+ JP = "www.yokoshibahikari.chiba.jp"
17
+ IT = "www.example.it"
18
+ COM = "www.example.com"
19
+
20
+ TIMES = (ARGV.first || 50_000).to_i
21
+
22
+ # Initialize
23
+ PublicSuffix.valid?("example.com")
24
+
25
+ Benchmark.bmbm(25) do |x|
26
+ x.report("NAME_SHORT") do
27
+ TIMES.times { PublicSuffix.valid?(NAME_SHORT) == true }
28
+ end
29
+ x.report("NAME_SHORT (noprivate)") do
30
+ TIMES.times { PublicSuffix.valid?(NAME_SHORT, ignore_private: true) == true }
31
+ end
32
+ x.report("NAME_MEDIUM") do
33
+ TIMES.times { PublicSuffix.valid?(NAME_MEDIUM) == true }
34
+ end
35
+ x.report("NAME_MEDIUM (noprivate)") do
36
+ TIMES.times { PublicSuffix.valid?(NAME_MEDIUM, ignore_private: true) == true }
37
+ end
38
+ x.report("NAME_LONG") do
39
+ TIMES.times { PublicSuffix.valid?(NAME_LONG) == true }
40
+ end
41
+ x.report("NAME_LONG (noprivate)") do
42
+ TIMES.times { PublicSuffix.valid?(NAME_LONG, ignore_private: true) == true }
43
+ end
44
+ x.report("NAME_WILD") do
45
+ TIMES.times { PublicSuffix.valid?(NAME_WILD) == true }
46
+ end
47
+ x.report("NAME_WILD (noprivate)") do
48
+ TIMES.times { PublicSuffix.valid?(NAME_WILD, ignore_private: true) == true }
49
+ end
50
+ x.report("NAME_EXCP") do
51
+ TIMES.times { PublicSuffix.valid?(NAME_EXCP) == true }
52
+ end
53
+ x.report("NAME_EXCP (noprivate)") do
54
+ TIMES.times { PublicSuffix.valid?(NAME_EXCP, ignore_private: true) == true }
55
+ end
56
+
57
+ x.report("IAAA") do
58
+ TIMES.times { PublicSuffix.valid?(IAAA) == true }
59
+ end
60
+ x.report("IAAA (noprivate)") do
61
+ TIMES.times { PublicSuffix.valid?(IAAA, ignore_private: true) == true }
62
+ end
63
+ x.report("IZZZ") do
64
+ TIMES.times { PublicSuffix.valid?(IZZZ) == true }
65
+ end
66
+ x.report("IZZZ (noprivate)") do
67
+ TIMES.times { PublicSuffix.valid?(IZZZ, ignore_private: true) == true }
68
+ end
69
+
70
+ x.report("PAAA") do
71
+ TIMES.times { PublicSuffix.valid?(PAAA) == true }
72
+ end
73
+ x.report("PAAA (noprivate)") do
74
+ TIMES.times { PublicSuffix.valid?(PAAA, ignore_private: true) == true }
75
+ end
76
+ x.report("PZZZ") do
77
+ TIMES.times { PublicSuffix.valid?(PZZZ) == true }
78
+ end
79
+ x.report("PZZZ (noprivate)") do
80
+ TIMES.times { PublicSuffix.valid?(PZZZ, ignore_private: true) == true }
81
+ end
82
+
83
+ x.report("JP") do
84
+ TIMES.times { PublicSuffix.valid?(JP) == true }
85
+ end
86
+ x.report("JP (noprivate)") do
87
+ TIMES.times { PublicSuffix.valid?(JP, ignore_private: true) == true }
88
+ end
89
+ x.report("IT") do
90
+ TIMES.times { PublicSuffix.valid?(IT) == true }
91
+ end
92
+ x.report("IT (noprivate)") do
93
+ TIMES.times { PublicSuffix.valid?(IT, ignore_private: true) == true }
94
+ end
95
+ x.report("COM") do
96
+ TIMES.times { PublicSuffix.valid?(COM) == true }
97
+ end
98
+ x.report("COM (noprivate)") do
99
+ TIMES.times { PublicSuffix.valid?(COM, ignore_private: true) == true }
100
+ end
101
+ end