public_suffix 5.0.1 → 5.0.5

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +9 -2
  5. data/SECURITY.md +2 -81
  6. data/data/list.txt +3256 -1855
  7. data/lib/public_suffix/domain.rb +1 -1
  8. data/lib/public_suffix/errors.rb +1 -1
  9. data/lib/public_suffix/list.rb +1 -1
  10. data/lib/public_suffix/rule.rb +1 -1
  11. data/lib/public_suffix/version.rb +3 -4
  12. data/lib/public_suffix.rb +1 -1
  13. metadata +8 -42
  14. data/.github/FUNDING.yml +0 -12
  15. data/.github/dependabot.yml +0 -19
  16. data/.github/workflows/psl-update.yml +0 -38
  17. data/.github/workflows/release.yml +0 -18
  18. data/.github/workflows/tests.yml +0 -29
  19. data/.gitignore +0 -8
  20. data/.rubocop.yml +0 -37
  21. data/.rubocop_opinionated.yml +0 -135
  22. data/Gemfile +0 -14
  23. data/Rakefile +0 -52
  24. data/bin/console +0 -15
  25. data/public_suffix.gemspec +0 -29
  26. data/test/.empty +0 -2
  27. data/test/acceptance_test.rb +0 -131
  28. data/test/benchmarks/bm_find.rb +0 -66
  29. data/test/benchmarks/bm_find_all.rb +0 -102
  30. data/test/benchmarks/bm_names.rb +0 -91
  31. data/test/benchmarks/bm_select.rb +0 -26
  32. data/test/benchmarks/bm_select_incremental.rb +0 -25
  33. data/test/benchmarks/bm_valid.rb +0 -101
  34. data/test/profilers/domain_profiler.rb +0 -12
  35. data/test/profilers/find_profiler.rb +0 -12
  36. data/test/profilers/find_profiler_jp.rb +0 -12
  37. data/test/profilers/initialization_profiler.rb +0 -11
  38. data/test/profilers/list_profsize.rb +0 -11
  39. data/test/profilers/object_binsize.rb +0 -57
  40. data/test/psl_test.rb +0 -52
  41. data/test/test_helper.rb +0 -10
  42. data/test/tests.txt +0 -98
  43. data/test/unit/domain_test.rb +0 -106
  44. data/test/unit/errors_test.rb +0 -25
  45. data/test/unit/list_test.rb +0 -241
  46. data/test/unit/public_suffix_test.rb +0 -188
  47. data/test/unit/rule_test.rb +0 -222
data/test/psl_test.rb DELETED
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "public_suffix"
5
-
6
- # This test runs against the current PSL file and ensures
7
- # the definitions satisfies the test suite.
8
- class PslTest < Minitest::Test
9
-
10
- ROOT = File.expand_path("..", __dir__)
11
-
12
- # rubocop:disable Security/Eval
13
- def self.tests
14
- File.readlines(File.join(ROOT, "test/tests.txt")).map do |line|
15
- line = line.strip
16
- next if line.empty?
17
- next if line.start_with?("//")
18
-
19
- input, output = line.split(", ")
20
-
21
- # handle the case of eval("null"), it must be eval("nil")
22
- input = "nil" if input == "null"
23
- output = "nil" if output == "null"
24
-
25
- input = eval(input)
26
- output = eval(output)
27
- [input, output]
28
- end
29
- end
30
- # rubocop:enable Security/Eval
31
-
32
-
33
- def test_valid
34
- # Parse the PSL and run the tests
35
- data = File.read(PublicSuffix::List::DEFAULT_LIST_PATH)
36
- PublicSuffix::List.default = PublicSuffix::List.parse(data)
37
-
38
- failures = []
39
- self.class.tests.each do |input, output|
40
- # Punycode domains are not supported ATM
41
- next if input =~ /xn--/
42
-
43
- domain = PublicSuffix.domain(input) rescue nil
44
- failures << [input, output, domain] if output != domain
45
- end
46
-
47
- message = "The following #{failures.size} tests fail:\n"
48
- failures.each { |i, o, d| message += format("Expected %s to be %s, got %s\n", i.inspect, o.inspect, d.inspect) }
49
- assert_equal 0, failures.size, message
50
- end
51
-
52
- end
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "minitest/autorun"
4
- require "minitest/reporters"
5
- require "mocha/minitest"
6
-
7
- Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
8
-
9
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
10
- require "public_suffix"
data/test/tests.txt DELETED
@@ -1,98 +0,0 @@
1
- // Any copyright is dedicated to the Public Domain.
2
- // http://creativecommons.org/publicdomain/zero/1.0/
3
-
4
- // null input
5
- null, null
6
- // Mixed case
7
- 'COM', null
8
- 'example.COM', 'example.com'
9
- 'WwW.example.COM', 'example.com'
10
- // Leading dot
11
- '.com', null
12
- '.example', null
13
- '.example.com', null
14
- '.example.example', null
15
- // Unlisted TLD
16
- 'example', null
17
- 'example.example', 'example.example'
18
- 'b.example.example', 'example.example'
19
- 'a.b.example.example', 'example.example'
20
- // Listed, but non-Internet, TLD
21
- //'local', null
22
- //'example.local', null
23
- //'b.example.local', null
24
- //'a.b.example.local', null
25
- // TLD with only 1 rule
26
- 'biz', null
27
- 'domain.biz', 'domain.biz'
28
- 'b.domain.biz', 'domain.biz'
29
- 'a.b.domain.biz', 'domain.biz'
30
- // TLD with some 2-level rules
31
- 'com', null
32
- 'example.com', 'example.com'
33
- 'b.example.com', 'example.com'
34
- 'a.b.example.com', 'example.com'
35
- 'uk.com', null
36
- 'example.uk.com', 'example.uk.com'
37
- 'b.example.uk.com', 'example.uk.com'
38
- 'a.b.example.uk.com', 'example.uk.com'
39
- 'test.ac', 'test.ac'
40
- // TLD with only 1 (wildcard) rule
41
- 'mm', null
42
- 'c.mm', null
43
- 'b.c.mm', 'b.c.mm'
44
- 'a.b.c.mm', 'b.c.mm'
45
- // More complex TLD
46
- 'jp', null
47
- 'test.jp', 'test.jp'
48
- 'www.test.jp', 'test.jp'
49
- 'ac.jp', null
50
- 'test.ac.jp', 'test.ac.jp'
51
- 'www.test.ac.jp', 'test.ac.jp'
52
- 'kyoto.jp', null
53
- 'test.kyoto.jp', 'test.kyoto.jp'
54
- 'ide.kyoto.jp', null
55
- 'b.ide.kyoto.jp', 'b.ide.kyoto.jp'
56
- 'a.b.ide.kyoto.jp', 'b.ide.kyoto.jp'
57
- 'c.kobe.jp', null
58
- 'b.c.kobe.jp', 'b.c.kobe.jp'
59
- 'a.b.c.kobe.jp', 'b.c.kobe.jp'
60
- 'city.kobe.jp', 'city.kobe.jp'
61
- 'www.city.kobe.jp', 'city.kobe.jp'
62
- // TLD with a wildcard rule and exceptions
63
- 'ck', null
64
- 'test.ck', null
65
- 'b.test.ck', 'b.test.ck'
66
- 'a.b.test.ck', 'b.test.ck'
67
- 'www.ck', 'www.ck'
68
- 'www.www.ck', 'www.ck'
69
- // US K12
70
- 'us', null
71
- 'test.us', 'test.us'
72
- 'www.test.us', 'test.us'
73
- 'ak.us', null
74
- 'test.ak.us', 'test.ak.us'
75
- 'www.test.ak.us', 'test.ak.us'
76
- 'k12.ak.us', null
77
- 'test.k12.ak.us', 'test.k12.ak.us'
78
- 'www.test.k12.ak.us', 'test.k12.ak.us'
79
- // IDN labels
80
- '食狮.com.cn', '食狮.com.cn'
81
- '食狮.公司.cn', '食狮.公司.cn'
82
- 'www.食狮.公司.cn', '食狮.公司.cn'
83
- 'shishi.公司.cn', 'shishi.公司.cn'
84
- '公司.cn', null
85
- '食狮.中国', '食狮.中国'
86
- 'www.食狮.中国', '食狮.中国'
87
- 'shishi.中国', 'shishi.中国'
88
- '中国', null
89
- // Same as above, but punycoded
90
- 'xn--85x722f.com.cn', 'xn--85x722f.com.cn'
91
- 'xn--85x722f.xn--55qx5d.cn', 'xn--85x722f.xn--55qx5d.cn'
92
- 'www.xn--85x722f.xn--55qx5d.cn', 'xn--85x722f.xn--55qx5d.cn'
93
- 'shishi.xn--55qx5d.cn', 'shishi.xn--55qx5d.cn'
94
- 'xn--55qx5d.cn', null
95
- 'xn--85x722f.xn--fiqs8s', 'xn--85x722f.xn--fiqs8s'
96
- 'www.xn--85x722f.xn--fiqs8s', 'xn--85x722f.xn--fiqs8s'
97
- 'shishi.xn--fiqs8s', 'shishi.xn--fiqs8s'
98
- 'xn--fiqs8s', null
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class PublicSuffix::DomainTest < Minitest::Test
6
-
7
- def setup
8
- @klass = PublicSuffix::Domain
9
- end
10
-
11
- # Tokenizes given input into labels.
12
- def test_self_name_to_labels
13
- assert_equal %w[someone spaces live com],
14
- PublicSuffix::Domain.name_to_labels("someone.spaces.live.com")
15
- assert_equal %w[leontina23samiko wiki zoho com],
16
- PublicSuffix::Domain.name_to_labels("leontina23samiko.wiki.zoho.com")
17
- end
18
-
19
- # Converts input into String.
20
- def test_self_name_to_labels_converts_input_to_string
21
- assert_equal %w[someone spaces live com],
22
- PublicSuffix::Domain.name_to_labels(:"someone.spaces.live.com")
23
- end
24
-
25
-
26
- def test_initialize_with_tld
27
- domain = @klass.new("com")
28
- assert_equal "com", domain.tld
29
- assert_nil domain.sld
30
- assert_nil domain.trd
31
- end
32
-
33
- def test_initialize_with_tld_and_sld
34
- domain = @klass.new("com", "google")
35
- assert_equal "com", domain.tld
36
- assert_equal "google", domain.sld
37
- assert_nil domain.trd
38
- end
39
-
40
- def test_initialize_with_tld_and_sld_and_trd
41
- domain = @klass.new("com", "google", "www")
42
- assert_equal "com", domain.tld
43
- assert_equal "google", domain.sld
44
- assert_equal "www", domain.trd
45
- end
46
-
47
-
48
- def test_to_s
49
- assert_equal "com", @klass.new("com").to_s
50
- assert_equal "google.com", @klass.new("com", "google").to_s
51
- assert_equal "www.google.com", @klass.new("com", "google", "www").to_s
52
- end
53
-
54
- def test_to_a
55
- assert_equal [nil, nil, "com"], @klass.new("com").to_a
56
- assert_equal [nil, "google", "com"], @klass.new("com", "google").to_a
57
- assert_equal ["www", "google", "com"], @klass.new("com", "google", "www").to_a
58
- end
59
-
60
-
61
- def test_tld
62
- assert_equal "com", @klass.new("com", "google", "www").tld
63
- end
64
-
65
- def test_sld
66
- assert_equal "google", @klass.new("com", "google", "www").sld
67
- end
68
-
69
- def test_trd
70
- assert_equal "www", @klass.new("com", "google", "www").trd
71
- end
72
-
73
-
74
- def test_name
75
- assert_equal "com", @klass.new("com").name
76
- assert_equal "google.com", @klass.new("com", "google").name
77
- assert_equal "www.google.com", @klass.new("com", "google", "www").name
78
- end
79
-
80
- def test_domain
81
- assert_nil @klass.new("com").domain
82
- assert_nil @klass.new("tldnotlisted").domain
83
- assert_equal "google.com", @klass.new("com", "google").domain
84
- assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google").domain
85
- assert_equal "google.com", @klass.new("com", "google", "www").domain
86
- assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").domain
87
- end
88
-
89
- def test_subdomain
90
- assert_nil @klass.new("com").subdomain
91
- assert_nil @klass.new("tldnotlisted").subdomain
92
- assert_nil @klass.new("com", "google").subdomain
93
- assert_nil @klass.new("tldnotlisted", "google").subdomain
94
- assert_equal "www.google.com", @klass.new("com", "google", "www").subdomain
95
- assert_equal "www.google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").subdomain
96
- end
97
-
98
-
99
- def test_domain_question
100
- assert !@klass.new("com").domain?
101
- assert @klass.new("com", "example").domain?
102
- assert @klass.new("com", "example", "www").domain?
103
- assert @klass.new("tldnotlisted", "example").domain?
104
- end
105
-
106
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ErrorsTest < Minitest::Test
6
-
7
- # Inherits from StandardError
8
- def test_error_inheritance
9
- assert_kind_of StandardError,
10
- PublicSuffix::Error.new
11
- end
12
-
13
- # Inherits from PublicSuffix::Error
14
- def test_domain_invalid_inheritance
15
- assert_kind_of PublicSuffix::Error,
16
- PublicSuffix::DomainInvalid.new
17
- end
18
-
19
- # Inherits from PublicSuffix::DomainInvalid
20
- def test_domain_not_allowed_inheritance
21
- assert_kind_of PublicSuffix::DomainInvalid,
22
- PublicSuffix::DomainNotAllowed.new
23
- end
24
-
25
- end
@@ -1,241 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class PublicSuffix::ListTest < Minitest::Test
6
-
7
- def setup
8
- @list = PublicSuffix::List.new
9
- end
10
-
11
- def teardown
12
- PublicSuffix::List.default = nil
13
- end
14
-
15
-
16
- def test_initialize
17
- assert_instance_of PublicSuffix::List, @list
18
- assert_equal 0, @list.size
19
- end
20
-
21
-
22
- def test_equality_with_self
23
- list = PublicSuffix::List.new
24
- assert_equal list, list
25
- end
26
-
27
- def test_equality_with_internals
28
- rule = PublicSuffix::Rule.factory("com")
29
- assert_equal PublicSuffix::List.new.add(rule), PublicSuffix::List.new.add(rule)
30
- end
31
-
32
- def test_each_without_block
33
- list = PublicSuffix::List.parse(<<LIST)
34
- alpha
35
- beta
36
- LIST
37
-
38
- assert_kind_of Enumerator, list.each
39
- assert_equal 2, list.each.count
40
- assert_equal PublicSuffix::Rule.factory("alpha"), list.each.first
41
- end
42
-
43
- def test_each_with_block
44
- list = PublicSuffix::List.parse(<<LIST)
45
- alpha
46
- beta
47
- LIST
48
-
49
- entries = []
50
- list.each { |r| entries << r }
51
-
52
- assert_equal 2, entries.count
53
- assert_equal PublicSuffix::Rule.factory("alpha"), entries.first
54
- end
55
-
56
-
57
- def test_add
58
- assert_equal @list, @list.add(PublicSuffix::Rule.factory("foo"))
59
- assert_equal @list, @list << PublicSuffix::Rule.factory("bar")
60
- assert_equal 2, @list.size
61
- end
62
-
63
- def test_add_should_recreate_index
64
- @list = PublicSuffix::List.parse("com")
65
- assert_equal PublicSuffix::Rule.factory("com"), @list.find("google.com")
66
- assert_equal @list.default_rule, @list.find("google.net")
67
-
68
- @list << PublicSuffix::Rule.factory("net")
69
- assert_equal PublicSuffix::Rule.factory("com"), @list.find("google.com")
70
- assert_equal PublicSuffix::Rule.factory("net"), @list.find("google.net")
71
- end
72
-
73
- def test_empty?
74
- assert @list.empty?
75
- @list.add(PublicSuffix::Rule.factory(""))
76
- assert !@list.empty?
77
- end
78
-
79
- def test_size
80
- assert_equal 0, @list.size
81
- assert_equal @list, @list.add(PublicSuffix::Rule.factory(""))
82
- assert_equal 1, @list.size
83
- end
84
-
85
- def test_clear
86
- assert_equal 0, @list.size
87
- assert_equal @list, @list.add(PublicSuffix::Rule.factory(""))
88
- assert_equal 1, @list.size
89
- assert_equal @list, @list.clear
90
- assert_equal 0, @list.size
91
- end
92
-
93
-
94
- def test_find
95
- list = PublicSuffix::List.parse(<<LIST)
96
- // This Source Code Form is subject to the terms of the Mozilla Public
97
- // License, v. 2.0. If a copy of the MPL was not distributed with this
98
- // file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
-
100
- // ===BEGIN ICANN DOMAINS===
101
-
102
- // com
103
- com
104
-
105
- // uk
106
- *.uk
107
- *.sch.uk
108
- !bl.uk
109
- !british-library.uk
110
-
111
- // io
112
- io
113
-
114
- // ===END ICANN DOMAINS===
115
- // ===BEGIN PRIVATE DOMAINS===
116
-
117
- // Google, Inc.
118
- blogspot.com
119
-
120
- // ===END PRIVATE DOMAINS===
121
- LIST
122
-
123
- # match IANA
124
- assert_equal PublicSuffix::Rule.factory("com"), list.find("example.com")
125
- assert_equal PublicSuffix::Rule.factory("com"), list.find("foo.example.com")
126
-
127
- # match wildcard
128
- assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.uk")
129
- assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("example.co.uk")
130
- assert_equal PublicSuffix::Rule.factory("*.uk"), list.find("foo.example.co.uk")
131
-
132
- # match exception
133
- assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("british-library.uk")
134
- assert_equal PublicSuffix::Rule.factory("!british-library.uk"), list.find("foo.british-library.uk")
135
-
136
- # match default rule
137
- assert_equal PublicSuffix::Rule.factory("*"), list.find("test")
138
- assert_equal PublicSuffix::Rule.factory("*"), list.find("example.test")
139
- assert_equal PublicSuffix::Rule.factory("*"), list.find("foo.example.test")
140
-
141
- # match private
142
- assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("blogspot.com")
143
- assert_equal PublicSuffix::Rule.factory("blogspot.com", private: true), list.find("foo.blogspot.com")
144
- end
145
-
146
-
147
- def test_select
148
- assert_equal 2, list.send(:select, "british-library.uk").size
149
- end
150
-
151
- def test_select_name_blank
152
- assert_equal [], list.send(:select, nil)
153
- assert_equal [], list.send(:select, "")
154
- assert_equal [], list.send(:select, " ")
155
- end
156
-
157
- def test_select_ignore_private
158
- list = PublicSuffix::List.new
159
- list.add r1 = PublicSuffix::Rule.factory("io")
160
- list.add r2 = PublicSuffix::Rule.factory("example.io", private: true)
161
-
162
- assert_equal list.send(:select, "foo.io"), [r1]
163
- assert_equal list.send(:select, "example.io"), [r1, r2]
164
- assert_equal list.send(:select, "foo.example.io"), [r1, r2]
165
-
166
- assert_equal list.send(:select, "foo.io", ignore_private: false), [r1]
167
- assert_equal list.send(:select, "example.io", ignore_private: false), [r1, r2]
168
- assert_equal list.send(:select, "foo.example.io", ignore_private: false), [r1, r2]
169
-
170
- assert_equal list.send(:select, "foo.io", ignore_private: true), [r1]
171
- assert_equal list.send(:select, "example.io", ignore_private: true), [r1]
172
- assert_equal list.send(:select, "foo.example.io", ignore_private: true), [r1]
173
- end
174
-
175
-
176
- def test_self_default_getter
177
- PublicSuffix::List.default = nil
178
- assert_nil(PublicSuffix::List.class_eval { @default })
179
- PublicSuffix::List.default
180
- refute_nil(PublicSuffix::List.class_eval { @default })
181
- end
182
-
183
- def test_self_default_setter
184
- PublicSuffix::List.default
185
- refute_nil(PublicSuffix::List.class_eval { @default })
186
- PublicSuffix::List.default = nil
187
- assert_nil(PublicSuffix::List.class_eval { @default })
188
- end
189
-
190
- def test_self_parse
191
- list = PublicSuffix::List.parse(<<LIST)
192
- // This Source Code Form is subject to the terms of the Mozilla Public
193
- // License, v. 2.0. If a copy of the MPL was not distributed with this
194
- // file, You can obtain one at https://mozilla.org/MPL/2.0/.
195
-
196
- // ===BEGIN ICANN DOMAINS===
197
-
198
- // com
199
- com
200
-
201
- // uk
202
- *.uk
203
- !british-library.uk
204
-
205
- // ===END ICANN DOMAINS===
206
- // ===BEGIN PRIVATE DOMAINS===
207
-
208
- // Google, Inc.
209
- blogspot.com
210
-
211
- // ===END PRIVATE DOMAINS===
212
- LIST
213
-
214
- assert_instance_of PublicSuffix::List, list
215
- assert_equal 4, list.size
216
-
217
- rules = %w[com *.uk !british-library.uk blogspot.com].map { |name| PublicSuffix::Rule.factory(name) }
218
- assert_equal rules, list.each.to_a
219
-
220
- # private domains
221
- assert_equal false, list.find("com").private
222
- assert_equal true, list.find("blogspot.com").private
223
- end
224
-
225
-
226
- private
227
-
228
- def list
229
- @_list ||= PublicSuffix::List.parse(<<LIST)
230
- // com : http://en.wikipedia.org/wiki/.com
231
- com
232
-
233
- // uk : http://en.wikipedia.org/wiki/.uk
234
- *.uk
235
- *.sch.uk
236
- !bl.uk
237
- !british-library.uk
238
- LIST
239
- end
240
-
241
- end