public_suffix 1.5.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_defaults.yml +127 -0
- data/.travis.yml +10 -5
- data/2.0-Upgrade.md +35 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +7 -1
- data/LICENSE.txt +1 -1
- data/README.md +89 -62
- data/Rakefile +23 -20
- data/data/{definitions.txt → list.txt} +472 -286
- data/lib/public_suffix.rb +96 -52
- data/lib/public_suffix/domain.rb +26 -156
- data/lib/public_suffix/errors.rb +5 -17
- data/lib/public_suffix/list.rb +107 -122
- data/lib/public_suffix/rule.rb +169 -190
- data/lib/public_suffix/version.rb +3 -13
- data/public_suffix.gemspec +4 -4
- data/test/acceptance_test.rb +57 -34
- data/test/benchmark_helper.rb +4 -0
- data/test/execution_profiler.rb +14 -0
- data/test/initialization_profiler.rb +11 -0
- data/test/performance_benchmark.rb +38 -0
- data/test/psl_test.rb +49 -0
- data/test/test_helper.rb +12 -5
- data/test/tests.txt +98 -0
- data/test/unit/domain_test.rb +18 -84
- data/test/unit/errors_test.rb +2 -2
- data/test/unit/list_test.rb +131 -59
- data/test/unit/public_suffix_test.rb +105 -34
- data/test/unit/rule_test.rb +52 -135
- metadata +20 -6
- data/.gemtest +0 -0
@@ -3,20 +3,10 @@
|
|
3
3
|
#
|
4
4
|
# Domain name parser based on the Public Suffix List.
|
5
5
|
#
|
6
|
-
# Copyright (c) 2009-
|
6
|
+
# Copyright (c) 2009-2016 Simone Carletti <weppos@weppos.net>
|
7
7
|
#
|
8
8
|
|
9
9
|
module PublicSuffix
|
10
|
-
|
11
|
-
|
12
|
-
MAJOR = 1
|
13
|
-
MINOR = 5
|
14
|
-
PATCH = 3
|
15
|
-
BUILD = nil
|
16
|
-
|
17
|
-
STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
|
18
|
-
end
|
19
|
-
|
20
|
-
VERSION = Version::STRING
|
21
|
-
|
10
|
+
# The current library version.
|
11
|
+
VERSION = "2.0.0".freeze
|
22
12
|
end
|
data/public_suffix.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: public_suffix 1.5.
|
2
|
+
# stub: public_suffix 1.5.3 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "public_suffix"
|
6
|
-
s.version = "1.5.
|
6
|
+
s.version = "1.5.3"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Simone Carletti"]
|
11
|
-
s.date = "2015-
|
11
|
+
s.date = "2015-12-14"
|
12
12
|
s.description = "PublicSuffix can parse and decompose a domain name into top level domain, domain and subdomains."
|
13
13
|
s.email = "weppos@weppos.net"
|
14
|
-
s.files = [".
|
14
|
+
s.files = [".gitignore", ".ruby-gemset", ".travis.yml", ".yardopts", "CHANGELOG.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "data/definitions.txt", "lib/public_suffix.rb", "lib/public_suffix/domain.rb", "lib/public_suffix/errors.rb", "lib/public_suffix/list.rb", "lib/public_suffix/rule.rb", "lib/public_suffix/version.rb", "public_suffix.gemspec", "test/acceptance_test.rb", "test/benchmark_helper.rb", "test/execution_profiler.rb", "test/initialization_profiler.rb", "test/performance_benchmark.rb", "test/psl_test.rb", "test/test_helper.rb", "test/tests.txt", "test/unit/domain_test.rb", "test/unit/errors_test.rb", "test/unit/list_test.rb", "test/unit/public_suffix_test.rb", "test/unit/rule_test.rb"]
|
15
15
|
s.homepage = "http://simonecarletti.com/code/publicsuffix"
|
16
16
|
s.licenses = ["MIT"]
|
17
17
|
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
data/test/acceptance_test.rb
CHANGED
@@ -1,46 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class AcceptanceTest < Minitest::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
|
-
["
|
7
|
-
["foo.
|
5
|
+
VALID_CASES = [
|
6
|
+
["example.com", "example.com", [nil, "example", "com"]],
|
7
|
+
["foo.example.com", "example.com", ["foo", "example", "com"]],
|
8
8
|
|
9
|
-
["verybritish.co.uk", [nil, "verybritish", "co.uk"]],
|
10
|
-
["foo.verybritish.co.uk", ["foo", "verybritish", "co.uk"]],
|
9
|
+
["verybritish.co.uk", "verybritish.co.uk", [nil, "verybritish", "co.uk"]],
|
10
|
+
["foo.verybritish.co.uk", "verybritish.co.uk", ["foo", "verybritish", "co.uk"]],
|
11
11
|
|
12
|
-
["parliament.uk", [nil, "parliament", "uk"]],
|
13
|
-
["foo.parliament.uk", ["foo", "parliament", "uk"]],
|
14
|
-
]
|
12
|
+
["parliament.uk", "parliament.uk", [nil, "parliament", "uk"]],
|
13
|
+
["foo.parliament.uk", "parliament.uk", ["foo", "parliament", "uk"]],
|
14
|
+
].freeze
|
15
15
|
|
16
16
|
def test_valid
|
17
|
-
|
18
|
-
|
17
|
+
VALID_CASES.each do |input, domain, results|
|
18
|
+
parsed = PublicSuffix.parse(input)
|
19
19
|
trd, sld, tld = results
|
20
|
-
assert_equal tld,
|
21
|
-
assert_equal sld,
|
22
|
-
assert_equal trd,
|
23
|
-
|
20
|
+
assert_equal tld, parsed.tld, "Invalid tld for `#{name}`"
|
21
|
+
assert_equal sld, parsed.sld, "Invalid sld for `#{name}`"
|
22
|
+
assert_equal trd, parsed.trd, "Invalid trd for `#{name}`"
|
23
|
+
|
24
|
+
assert_equal domain, PublicSuffix.domain(input)
|
25
|
+
assert PublicSuffix.valid?(input)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
|
28
|
-
|
30
|
+
INVALID_CASES = [
|
29
31
|
["nic.ke", PublicSuffix::DomainNotAllowed],
|
30
32
|
[nil, PublicSuffix::DomainInvalid],
|
31
33
|
["", PublicSuffix::DomainInvalid],
|
32
34
|
[" ", PublicSuffix::DomainInvalid],
|
33
|
-
]
|
35
|
+
].freeze
|
34
36
|
|
35
37
|
def test_invalid
|
36
|
-
|
38
|
+
INVALID_CASES.each do |(name, error)|
|
37
39
|
assert_raises(error) { PublicSuffix.parse(name) }
|
38
40
|
assert !PublicSuffix.valid?(name)
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
|
43
|
-
|
45
|
+
REJECTED_CASES = [
|
44
46
|
["www. .com", true],
|
45
47
|
["foo.co..uk", true],
|
46
48
|
["goo,gle.com", true],
|
@@ -48,27 +50,29 @@ class AcceptanceTest < Minitest::Unit::TestCase
|
|
48
50
|
["google-.com", true],
|
49
51
|
|
50
52
|
# This case was covered in GH-15.
|
51
|
-
# I
|
53
|
+
# I decided to cover this case because it's not easily reproducible with URI.parse
|
52
54
|
# and can lead to several false positives.
|
53
55
|
["http://google.com", false],
|
54
|
-
]
|
56
|
+
].freeze
|
55
57
|
|
56
58
|
def test_rejected
|
57
|
-
|
58
|
-
assert_equal expected, PublicSuffix.valid?(name)
|
59
|
-
|
59
|
+
REJECTED_CASES.each do |name, expected|
|
60
|
+
assert_equal expected, PublicSuffix.valid?(name),
|
61
|
+
"Expected %s to be %s" % [name.inspect, expected.inspect]
|
62
|
+
assert !valid_domain?(name),
|
63
|
+
"#{name} expected to be invalid"
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
["Www.google.com",
|
66
|
-
["www.Google.com",
|
67
|
-
["www.google.Com",
|
68
|
-
]
|
67
|
+
|
68
|
+
CASE_CASES = [
|
69
|
+
["Www.google.com", %w( www google com )],
|
70
|
+
["www.Google.com", %w( www google com )],
|
71
|
+
["www.google.Com", %w( www google com )],
|
72
|
+
].freeze
|
69
73
|
|
70
74
|
def test_ignore_case
|
71
|
-
|
75
|
+
CASE_CASES.each do |name, results|
|
72
76
|
domain = PublicSuffix.parse(name)
|
73
77
|
trd, sld, tld = results
|
74
78
|
assert_equal tld, domain.tld, "Invalid tld for `#{name}'"
|
@@ -79,18 +83,37 @@ class AcceptanceTest < Minitest::Unit::TestCase
|
|
79
83
|
end
|
80
84
|
|
81
85
|
|
86
|
+
INCLUDE_PRIVATE_CASES = [
|
87
|
+
["blogspot.com", true, "blogspot.com"],
|
88
|
+
["blogspot.com", false, nil],
|
89
|
+
["subdomain.blogspot.com", true, "blogspot.com"],
|
90
|
+
["subdomain.blogspot.com", false, "subdomain.blogspot.com"],
|
91
|
+
].freeze
|
92
|
+
|
93
|
+
def test_ignore_private
|
94
|
+
# test domain and parse
|
95
|
+
INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
|
96
|
+
assert_equal expected, PublicSuffix.domain(given, ignore_private: ignore_private)
|
97
|
+
end
|
98
|
+
# test valid?
|
99
|
+
INCLUDE_PRIVATE_CASES.each do |given, ignore_private, expected|
|
100
|
+
assert_equal !expected.nil?, PublicSuffix.valid?(given, ignore_private: ignore_private)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
82
105
|
def valid_uri?(name)
|
83
106
|
uri = URI.parse(name)
|
84
|
-
uri.host
|
107
|
+
!uri.host.nil?
|
85
108
|
rescue
|
86
109
|
false
|
87
110
|
end
|
88
111
|
|
89
112
|
def valid_domain?(name)
|
90
113
|
uri = URI.parse(name)
|
91
|
-
uri.host
|
114
|
+
!uri.host.nil? && uri.scheme.nil?
|
92
115
|
rescue
|
93
116
|
false
|
94
117
|
end
|
95
118
|
|
96
|
-
end
|
119
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require "memory_profiler"
|
4
|
+
require "public_suffix"
|
5
|
+
|
6
|
+
PublicSuffix::List.default
|
7
|
+
|
8
|
+
report = MemoryProfiler.report do
|
9
|
+
PublicSuffix.domain("www.example.com")
|
10
|
+
PublicSuffix.domain("a.b.ide.kyoto.jp")
|
11
|
+
end
|
12
|
+
|
13
|
+
report.pretty_print
|
14
|
+
# report.pretty_print(to_file: 'profiler-%s-%d.txt' % [ARGV[0], Time.now.to_i])
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require "memory_profiler"
|
4
|
+
require "public_suffix"
|
5
|
+
|
6
|
+
report = MemoryProfiler.report do
|
7
|
+
PublicSuffix::List.default
|
8
|
+
end
|
9
|
+
|
10
|
+
report.pretty_print
|
11
|
+
# report.pretty_print(to_file: 'profiler-%s-%d.txt' % [ARGV[0], Time.now.to_i])
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "benchmark_helper"
|
2
|
+
|
3
|
+
iterations = 100_000
|
4
|
+
|
5
|
+
# force load
|
6
|
+
list = PublicSuffix::List.default
|
7
|
+
|
8
|
+
Benchmark.bmbm do |bm|
|
9
|
+
bm.report "Top level TLD" do
|
10
|
+
iterations.times do
|
11
|
+
PublicSuffix.domain("example.com", list)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
bm.report "Top level TLD (subdomain)" do
|
16
|
+
iterations.times do
|
17
|
+
PublicSuffix.domain("www.example.com", list)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
bm.report "Unlisted TLD" do
|
22
|
+
iterations.times do
|
23
|
+
PublicSuffix.domain("example.example", list)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
bm.report "Unlisted TLD (subdomain)" do
|
28
|
+
iterations.times do
|
29
|
+
PublicSuffix.domain("www.example.example", list)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
bm.report "Crazy suffix" do
|
34
|
+
iterations.times do
|
35
|
+
PublicSuffix.domain("a.b.ide.kyoto.jp", list)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/psl_test.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "public_suffix"
|
3
|
+
|
4
|
+
# This test runs against the current PSL file and ensures
|
5
|
+
# the definitions satisfies the test suite.
|
6
|
+
class PslTest < Minitest::Unit::TestCase
|
7
|
+
|
8
|
+
ROOT = File.expand_path("../../", __FILE__)
|
9
|
+
|
10
|
+
# rubocop:disable Lint/Eval
|
11
|
+
def self.tests
|
12
|
+
File.readlines(File.join(ROOT, "test/tests.txt")).map do |line|
|
13
|
+
line = line.strip
|
14
|
+
next if line.empty?
|
15
|
+
next if line.start_with?("//")
|
16
|
+
input, output = line.split(", ")
|
17
|
+
|
18
|
+
# handle the case of eval("null"), it must be eval("nil")
|
19
|
+
input = "nil" if input == "null"
|
20
|
+
output = "nil" if output == "null"
|
21
|
+
|
22
|
+
input = eval(input)
|
23
|
+
output = eval(output)
|
24
|
+
[input, output]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# rubocop:enable
|
28
|
+
|
29
|
+
|
30
|
+
def test_valid
|
31
|
+
# Parse the PSL and run the tests
|
32
|
+
data = File.read(PublicSuffix::List::DEFAULT_LIST_PATH)
|
33
|
+
PublicSuffix::List.default = PublicSuffix::List.parse(data)
|
34
|
+
|
35
|
+
failures = []
|
36
|
+
self.class.tests.each do |input, output|
|
37
|
+
# Punycode domains are not supported ATM
|
38
|
+
next if input =~ /xn\-\-/
|
39
|
+
|
40
|
+
domain = PublicSuffix.domain(input) rescue nil
|
41
|
+
failures << [input, output, domain] if output != domain
|
42
|
+
end
|
43
|
+
|
44
|
+
message = "The following #{failures.size} tests fail:\n"
|
45
|
+
failures.each { |i, o, d| message += "Expected %s to be %s, got %s\n" % [i.inspect, o.inspect, d.inspect] }
|
46
|
+
assert_equal 0, failures.size, message
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
1
|
+
if ENV["COVERALL"]
|
2
|
+
require "coveralls"
|
3
|
+
Coveralls.wear!
|
4
|
+
end
|
5
|
+
|
6
|
+
require "minitest/autorun"
|
7
|
+
require "minitest/reporters"
|
8
|
+
require "mocha/setup"
|
9
|
+
|
10
|
+
Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
|
4
11
|
|
5
|
-
|
6
|
-
require
|
12
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
13
|
+
require "public_suffix"
|
7
14
|
|
8
15
|
Minitest::Unit::TestCase.class_eval do
|
9
16
|
def assert_not_equal(exp, act, msg = nil)
|
data/test/tests.txt
ADDED
@@ -0,0 +1,98 @@
|
|
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
|
data/test/unit/domain_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class PublicSuffix::DomainTest < Minitest::Unit::TestCase
|
4
4
|
|
@@ -7,25 +7,17 @@ class PublicSuffix::DomainTest < Minitest::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# Tokenizes given input into labels.
|
10
|
-
def
|
11
|
-
assert_equal %w(
|
12
|
-
PublicSuffix::Domain.
|
13
|
-
assert_equal %w(
|
14
|
-
PublicSuffix::Domain.
|
10
|
+
def test_self_name_to_labels
|
11
|
+
assert_equal %w( someone spaces live com ),
|
12
|
+
PublicSuffix::Domain.name_to_labels("someone.spaces.live.com")
|
13
|
+
assert_equal %w( leontina23samiko wiki zoho com ),
|
14
|
+
PublicSuffix::Domain.name_to_labels("leontina23samiko.wiki.zoho.com")
|
15
15
|
end
|
16
16
|
|
17
17
|
# Converts input into String.
|
18
|
-
def
|
19
|
-
assert_equal %w(
|
20
|
-
PublicSuffix::Domain.
|
21
|
-
end
|
22
|
-
|
23
|
-
# Ignores trailing .
|
24
|
-
def test_self_domain_to_labels_ignores_trailing_dot
|
25
|
-
assert_equal %w( com live spaces someone ),
|
26
|
-
PublicSuffix::Domain.domain_to_labels("someone.spaces.live.com")
|
27
|
-
assert_equal %w( com live spaces someone ),
|
28
|
-
PublicSuffix::Domain.domain_to_labels(:"someone.spaces.live.com")
|
18
|
+
def test_self_name_to_labels_converts_input_to_string
|
19
|
+
assert_equal %w( someone spaces live com ),
|
20
|
+
PublicSuffix::Domain.name_to_labels(:"someone.spaces.live.com")
|
29
21
|
end
|
30
22
|
|
31
23
|
|
@@ -85,86 +77,28 @@ class PublicSuffix::DomainTest < Minitest::Unit::TestCase
|
|
85
77
|
|
86
78
|
def test_domain
|
87
79
|
assert_equal nil, @klass.new("com").domain
|
88
|
-
assert_equal nil, @klass.new("
|
80
|
+
assert_equal nil, @klass.new("tldnotlisted").domain
|
89
81
|
assert_equal "google.com", @klass.new("com", "google").domain
|
90
|
-
assert_equal "google.
|
82
|
+
assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google").domain
|
91
83
|
assert_equal "google.com", @klass.new("com", "google", "www").domain
|
92
|
-
assert_equal "google.
|
84
|
+
assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").domain
|
93
85
|
end
|
94
86
|
|
95
87
|
def test_subdomain
|
96
88
|
assert_equal nil, @klass.new("com").subdomain
|
97
|
-
assert_equal nil, @klass.new("
|
89
|
+
assert_equal nil, @klass.new("tldnotlisted").subdomain
|
98
90
|
assert_equal nil, @klass.new("com", "google").subdomain
|
99
|
-
assert_equal nil, @klass.new("
|
91
|
+
assert_equal nil, @klass.new("tldnotlisted", "google").subdomain
|
100
92
|
assert_equal "www.google.com", @klass.new("com", "google", "www").subdomain
|
101
|
-
assert_equal "www.google.
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_rule
|
105
|
-
assert_equal nil, @klass.new("qqq").rule
|
106
|
-
assert_equal PublicSuffix::Rule.factory("com"), @klass.new("com").rule
|
107
|
-
assert_equal PublicSuffix::Rule.factory("com"), @klass.new("com", "google").rule
|
108
|
-
assert_equal PublicSuffix::Rule.factory("com"), @klass.new("com", "google", "www").rule
|
93
|
+
assert_equal "www.google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").subdomain
|
109
94
|
end
|
110
95
|
|
111
96
|
|
112
97
|
def test_domain_question
|
113
|
-
assert @klass.new("com", "google").domain?
|
114
|
-
assert @klass.new("qqq", "google").domain?
|
115
|
-
assert @klass.new("com", "google", "www").domain?
|
116
98
|
assert !@klass.new("com").domain?
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
assert @klass.new("com", "google", "www").subdomain?
|
121
|
-
assert @klass.new("qqq", "google", "www").subdomain?
|
122
|
-
assert !@klass.new("com").subdomain?
|
123
|
-
assert !@klass.new("com", "google").subdomain?
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_is_a_domain_question
|
127
|
-
assert @klass.new("com", "google").is_a_domain?
|
128
|
-
assert @klass.new("qqq", "google").is_a_domain?
|
129
|
-
assert !@klass.new("com", "google", "www").is_a_domain?
|
130
|
-
assert !@klass.new("com").is_a_domain?
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_is_a_subdomain_question
|
134
|
-
assert @klass.new("com", "google", "www").is_a_subdomain?
|
135
|
-
assert @klass.new("qqq", "google", "www").is_a_subdomain?
|
136
|
-
assert !@klass.new("com").is_a_subdomain?
|
137
|
-
assert !@klass.new("com", "google").is_a_subdomain?
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_valid_question
|
141
|
-
assert !@klass.new("com").valid?
|
142
|
-
assert @klass.new("com", "example").valid?
|
143
|
-
assert @klass.new("com", "example", "www").valid?
|
144
|
-
|
145
|
-
# not-assigned
|
146
|
-
assert !@klass.new("qqq").valid?
|
147
|
-
assert !@klass.new("qqq", "example").valid?
|
148
|
-
assert !@klass.new("qqq", "example", "www").valid?
|
149
|
-
|
150
|
-
# not-allowed
|
151
|
-
assert !@klass.new("ke").valid?
|
152
|
-
assert !@klass.new("ke", "example").valid?
|
153
|
-
assert @klass.new("ke", "example", "www").valid?
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_valid_domain_question
|
157
|
-
assert @klass.new("com", "google").valid_domain?
|
158
|
-
assert !@klass.new("qqq", "google").valid_domain?
|
159
|
-
assert @klass.new("com", "google", "www").valid_domain?
|
160
|
-
assert !@klass.new("com").valid_domain?
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_valid_subdomain_question
|
164
|
-
assert @klass.new("com", "google", "www").valid_subdomain?
|
165
|
-
assert !@klass.new("qqq", "google", "www").valid_subdomain?
|
166
|
-
assert !@klass.new("com").valid_subdomain?
|
167
|
-
assert !@klass.new("com", "google").valid_subdomain?
|
99
|
+
assert @klass.new("com", "example").domain?
|
100
|
+
assert @klass.new("com", "example", "www").domain?
|
101
|
+
assert @klass.new("tldnotlisted", "example").domain?
|
168
102
|
end
|
169
103
|
|
170
104
|
end
|