public_suffix_service 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +10 -0
- data/lib/public_suffix_service.rb +7 -4
- data/lib/public_suffix_service/errors.rb +28 -1
- data/lib/public_suffix_service/version.rb +2 -2
- data/public_suffix_service.gemspec +2 -2
- data/test/acceptance_test.rb +13 -3
- data/test/public_suffix_service/rule_test.rb +8 -1
- data/test/public_suffix_service_test.rb +1 -1
- metadata +5 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
= Changelog
|
2
2
|
|
3
|
+
== Release 0.6.0
|
4
|
+
|
5
|
+
* ADDED: PublicSuffixService.parse raises DomainNotAllowed when trying to parse a domain name
|
6
|
+
which exists, but is not allowed by the current definition list (#3)
|
7
|
+
|
8
|
+
PublicSuffixService.parse("nic.do")
|
9
|
+
# => PublicSuffixService::DomainNotAllowed
|
10
|
+
|
11
|
+
* CHANGED: Renamed PublicSuffixService::InvalidDomain to PublicSuffixService::DomainInvalid
|
12
|
+
|
3
13
|
|
4
14
|
== Release 0.5.2
|
5
15
|
|
@@ -42,20 +42,23 @@ module PublicSuffixService
|
|
42
42
|
# # => #<PubliSuffixService::Domain ...>
|
43
43
|
#
|
44
44
|
# PublicSuffixService.parse("http://www.google.com")
|
45
|
-
# # => PublicSuffixService::
|
45
|
+
# # => PublicSuffixService::DomainInvalid
|
46
46
|
#
|
47
47
|
# PublicSuffixService.parse("x.yz")
|
48
|
-
# # => PublicSuffixService::
|
48
|
+
# # => PublicSuffixService::DomainInvalid
|
49
49
|
#
|
50
50
|
# Raises PublicSuffixService::Error if domain is not a valid domain
|
51
51
|
#
|
52
52
|
# Returns the PubliSuffixService::Domain domain.
|
53
53
|
def self.parse(domain)
|
54
|
-
rule = RuleList.default.find(domain) || raise(
|
54
|
+
rule = RuleList.default.find(domain) || raise(DomainInvalid, "`#{domain}' is not a valid domain")
|
55
55
|
|
56
56
|
left, right = rule.decompose(domain)
|
57
|
-
|
57
|
+
if right.nil?
|
58
|
+
raise DomainNotAllowed, "Rule `#{rule.name}' doesn't allow `#{domain}'"
|
59
|
+
end
|
58
60
|
|
61
|
+
parts = left.split(".")
|
59
62
|
# If we have 0 parts left, there is just a tld and no domain or subdomain
|
60
63
|
# If we have 1 part left, there is just a tld, domain and not subdomain
|
61
64
|
# If we have 2 parts left, the last part is the domain, the other parts (combined) are the subdomain
|
@@ -19,7 +19,34 @@ module PublicSuffixService
|
|
19
19
|
class Error < StandardError
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
# Raised when trying to parse an invalid domain.
|
23
|
+
# A domain is considered invalid when no rule is found
|
24
|
+
# in the definition list.
|
25
|
+
#
|
26
|
+
# Since 0.6.0
|
27
|
+
class DomainInvalid < Error
|
23
28
|
end
|
24
29
|
|
30
|
+
# Raised when trying to parse a domain
|
31
|
+
# which is formally defined by a rule,
|
32
|
+
# but the rules set a requirement which is not satisfied
|
33
|
+
# by the input you are trying to parse.
|
34
|
+
#
|
35
|
+
# Since 0.6.0
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# PublicSuffixService.parse("nic.do")
|
40
|
+
# # => PublicSuffixService::DomainNotAllowed
|
41
|
+
#
|
42
|
+
# PublicSuffixService.parse("www.nic.do")
|
43
|
+
# # => PublicSuffixService::Domain
|
44
|
+
#
|
45
|
+
class DomainNotAllowed < DomainInvalid
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
# Backward Compatibility
|
50
|
+
InvalidDomain = DomainInvalid
|
51
|
+
|
25
52
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{public_suffix_service}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Simone Carletti"]
|
9
|
-
s.date = %q{2010-09-
|
9
|
+
s.date = %q{2010-09-17}
|
10
10
|
s.description = %q{ Intelligent domain name parser based in the Public Suffic List. PublicSuffixService can parse and decompose a domain name into top level domain, domain and subdomains.
|
11
11
|
}
|
12
12
|
s.email = %q{weppos@weppos.net}
|
data/test/acceptance_test.rb
CHANGED
@@ -2,7 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class AcceptanceTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
ValidCases = {
|
6
6
|
"google.com" => [nil, "google", "com"],
|
7
7
|
"foo.google.com" => ["foo", "google", "com"],
|
8
8
|
|
@@ -13,8 +13,8 @@ class AcceptanceTest < Test::Unit::TestCase
|
|
13
13
|
"foo.parliament.uk" => ["foo", "parliament", "uk"],
|
14
14
|
}
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def test_valid
|
17
|
+
ValidCases.each do |name, results|
|
18
18
|
domain = PublicSuffixService.parse(name)
|
19
19
|
trd, sld, tld = results
|
20
20
|
assert_equal tld, domain.tld, "Invalid tld for '#{name}'"
|
@@ -23,4 +23,14 @@ class AcceptanceTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
InvalidCases = {
|
27
|
+
"nic.do" => PublicSuffixService::DomainNotAllowed,
|
28
|
+
}
|
29
|
+
|
30
|
+
def test_invalid
|
31
|
+
InvalidCases.each do |name, error|
|
32
|
+
assert_raise(error) { PublicSuffixService.parse(name) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
end
|
@@ -3,6 +3,9 @@ require 'test_helper'
|
|
3
3
|
class PublicSuffixService::RuleTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_factory_should_return_rule_normal
|
6
|
+
rule = PublicSuffixService::Rule.factory("com")
|
7
|
+
assert_instance_of PublicSuffixService::Rule::Normal, rule
|
8
|
+
|
6
9
|
rule = PublicSuffixService::Rule.factory("verona.it")
|
7
10
|
assert_instance_of PublicSuffixService::Rule::Normal, rule
|
8
11
|
end
|
@@ -13,7 +16,10 @@ class PublicSuffixService::RuleTest < Test::Unit::TestCase
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_factory_should_return_rule_wildcard
|
16
|
-
rule = PublicSuffixService::Rule.factory("*.
|
19
|
+
rule = PublicSuffixService::Rule.factory("*.do")
|
20
|
+
assert_instance_of PublicSuffixService::Rule::Wildcard, rule
|
21
|
+
|
22
|
+
rule = PublicSuffixService::Rule.factory("*.sch.uk")
|
17
23
|
assert_instance_of PublicSuffixService::Rule::Wildcard, rule
|
18
24
|
end
|
19
25
|
|
@@ -208,6 +214,7 @@ class PublicSuffixService::RuleWildcardTest < Test::Unit::TestCase
|
|
208
214
|
end
|
209
215
|
|
210
216
|
def test_decompose
|
217
|
+
assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do")
|
211
218
|
assert_equal %w(google co.uk), @klass.new("*.uk").decompose("google.co.uk")
|
212
219
|
assert_equal %w(foo.google co.uk), @klass.new("*.uk").decompose("foo.google.co.uk")
|
213
220
|
end
|
@@ -45,7 +45,7 @@ class PublicSuffixServiceTest < Test::Unit::TestCase
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_self_parse_should_raise_with_invalid_domain
|
48
|
-
error = assert_raise(PublicSuffixService::
|
48
|
+
error = assert_raise(PublicSuffixService::DomainInvalid) { PublicSuffixService.parse("google.zip") }
|
49
49
|
assert_match %r{google\.zip}, error.message
|
50
50
|
end
|
51
51
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: public_suffix_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Simone Carletti
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-18 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|