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 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::InvalidDomain
45
+ # # => PublicSuffixService::DomainInvalid
46
46
  #
47
47
  # PublicSuffixService.parse("x.yz")
48
- # # => PublicSuffixService::InvalidDomain
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(InvalidDomain, "`#{domain}' is not a valid domain")
54
+ rule = RuleList.default.find(domain) || raise(DomainInvalid, "`#{domain}' is not a valid domain")
55
55
 
56
56
  left, right = rule.decompose(domain)
57
- parts = left.split(".")
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
- class InvalidDomain < Error
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
@@ -18,8 +18,8 @@ module PublicSuffixService
18
18
 
19
19
  module Version
20
20
  MAJOR = 0
21
- MINOR = 5
22
- PATCH = 2
21
+ MINOR = 6
22
+ PATCH = 0
23
23
  BUILD = nil
24
24
 
25
25
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
@@ -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.1"
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-15}
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}
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class AcceptanceTest < Test::Unit::TestCase
4
4
 
5
- CASES = {
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 test_all
17
- CASES.each do |name, results|
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("*.aichi.jp")
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::InvalidDomain) { PublicSuffixService.parse("google.zip") }
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: 15
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
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-17 00:00:00 +02:00
18
+ date: 2010-09-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency