public_suffix_service 0.7.0 → 0.8.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.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,13 @@
1
1
  = Changelog
2
2
 
3
+
4
+ == Release 0.8.0
5
+
6
+ * CHANGED: Update public suffix list to d1a5599b49fa 2010-10-25 15:10 +0100 (#9)
7
+
8
+ * NEW: Add support for Fully Qualified Domain Names (#7)
9
+
10
+
3
11
  == Release 0.7.0
4
12
 
5
13
  * CHANGED: Using YARD to document the code instead of RDoc.
data/README.rdoc CHANGED
@@ -50,7 +50,7 @@ The best way to install Public Suffix Service< is via {RubyGems}[http://www.ruby
50
50
  You might need administrator privileges on your system to install the Gem.
51
51
 
52
52
 
53
- == Usage
53
+ == Basic Usage
54
54
 
55
55
  Example domain without subdomains.
56
56
 
@@ -93,6 +93,22 @@ Simple validation example.
93
93
  PublicSuffixService.valid?("x.yz")
94
94
  # => false
95
95
 
96
+ == Fully Qualified Domain Names
97
+
98
+ This library automatically recognizes Fully Qualified Domain Names. A FQDN is a domain name that end with a trailing dot.
99
+
100
+ # Parse a standard domain name
101
+ domain = PublicSuffixService.parse("www.google.com")
102
+ # => #<PublicSuffixService::Domain>
103
+ domain.tld
104
+ # => "com"
105
+
106
+ # Parse a fully qualified domain name
107
+ domain = PublicSuffixService.parse("www.google.com.")
108
+ # => #<PublicSuffixService::Domain>
109
+ domain.tld
110
+ # => "com"
111
+
96
112
 
97
113
  == Credits
98
114
 
data/Rakefile CHANGED
@@ -55,11 +55,11 @@ spec = Gem::Specification.new do |s|
55
55
  # You should probably have a README of some kind. Change the filename
56
56
  # as appropriate
57
57
  s.extra_rdoc_files = Dir.glob("*.rdoc")
58
- s.rdoc_options = %w(--main README.rdoc)
58
+ s.rdoc_options = %w( --main README.rdoc )
59
59
 
60
60
  # Add any extra files to include in the gem (like your README)
61
- s.files = %w(Rakefile) + Dir.glob("*.{rdoc,gemspec}") + Dir.glob("{test,lib}/**/*")
62
- s.require_paths = ["lib"]
61
+ s.files = %w( Rakefile ) + Dir.glob("*.{rdoc,gemspec}") + Dir.glob("{test,lib}/**/*")
62
+ s.require_paths = %w( lib )
63
63
 
64
64
  # If you want to depend on other gems, add them here, along with any
65
65
  # relevant versions
@@ -95,27 +95,13 @@ desc "Package the library and generates the gemspec"
95
95
  task :package => [:gemspec]
96
96
 
97
97
 
98
- desc "Generate RDoc documentation"
99
- Rake::RDocTask.new do |r|
100
- r.main = "README.rdoc"
101
- r.rdoc_files.include("*.rdoc", "lib/**/*.rb")
102
- r.rdoc_dir = "rdoc"
103
- end
104
-
105
- namespace :rdoc do
106
- desc "Publish RDoc documentation to the site"
107
- task :publish => [:clobber_rdoc, :rdoc] do
108
- ENV["username"] || raise(ArgumentError, "Missing ssh username")
109
- sh "rsync -avz --delete rdoc/ #{ENV["username"]}@code:/var/www/apps/code/#{PKG_NAME}/rdoc"
110
- end
111
- end
112
-
113
-
114
98
  begin
115
99
  require "yard"
116
100
  require "yard/rake/yardoc_task"
117
101
 
118
- YARD::Rake::YardocTask.new(:yardoc)
102
+ YARD::Rake::YardocTask.new(:yardoc) do |y|
103
+ y.options = ["--output-dir", "yardoc"]
104
+ end
119
105
 
120
106
  namespace :yardoc do
121
107
  desc "Publish YARD documentation to the site"
@@ -155,17 +141,6 @@ task :console do
155
141
  sh "irb -rubygems -I lib -r public_suffix_service.rb"
156
142
  end
157
143
 
158
- begin
159
- require "code_statistics"
160
- desc "Show library's code statistics"
161
- task :stats do
162
- CodeStatistics.new(["Public Suffix Service", "lib"],
163
- ["Tests", "test"]).to_s
164
- end
165
- rescue LoadError
166
- puts "CodeStatistics (Rails) is not available"
167
- end
168
-
169
144
 
170
145
  desc <<-DESC
171
146
  Downloads the Public Suffix List file from the repository \
@@ -711,7 +711,6 @@ operaunite.com
711
711
 
712
712
  // Requested by Eduardo Vela <evn@google.com> 2010-09-06
713
713
  appspot.com
714
- blogspot.com
715
714
 
716
715
  // coop : http://en.wikipedia.org/wiki/.coop
717
716
  coop
@@ -4240,6 +4239,7 @@ mil.to
4240
4239
  // tr : http://en.wikipedia.org/wiki/.tr
4241
4240
  *.tr
4242
4241
  !nic.tr
4242
+ !tsk.tr
4243
4243
  // Used by government in the TRNC
4244
4244
  // http://en.wikipedia.org/wiki/.nc.tr
4245
4245
  gov.nc.tr
@@ -4290,11 +4290,14 @@ club.tw
4290
4290
 
4291
4291
  // tz : http://en.wikipedia.org/wiki/.tz
4292
4292
  // Submitted by registry <randy@psg.com> 2008-06-17
4293
+ // Updated from http://www.tznic.or.tz/index.php/domains.html 2010-10-25
4293
4294
  ac.tz
4294
4295
  co.tz
4295
4296
  go.tz
4297
+ mil.tz
4296
4298
  ne.tz
4297
4299
  or.tz
4300
+ sc.tz
4298
4301
 
4299
4302
  // ua : http://www.nic.net.ua/
4300
4303
  ua
@@ -197,7 +197,7 @@ module PublicSuffixService
197
197
  #
198
198
  # @example
199
199
  # rule = Rule.factory("*.do")
200
- # # #<PublicSuffixService::Rule::Wildcard>
200
+ # # => #<PublicSuffixService::Rule::Wildcard>
201
201
  # rule.allow?("example.do")
202
202
  # # => false
203
203
  # rule.allow?("www.example.do")
@@ -278,7 +278,7 @@ module PublicSuffixService
278
278
  # The array with [trd + sld, tld].
279
279
  #
280
280
  def decompose(domain)
281
- domain.to_s =~ /^(.*)\.(#{parts.join('\.')})$/
281
+ domain.to_s.chomp(".") =~ /^(.*)\.(#{parts.join('\.')})$/
282
282
  [$1, $2]
283
283
  end
284
284
 
@@ -320,7 +320,7 @@ module PublicSuffixService
320
320
  # The array with [trd + sld, tld].
321
321
  #
322
322
  def decompose(domain)
323
- domain.to_s =~ /^(.*)\.(.*?\.#{parts.join('\.')})$/
323
+ domain.to_s.chomp(".") =~ /^(.*)\.(.*?\.#{parts.join('\.')})$/
324
324
  [$1, $2]
325
325
  end
326
326
 
@@ -358,7 +358,7 @@ module PublicSuffixService
358
358
  # The array with [trd + sld, tld].
359
359
  #
360
360
  def decompose(domain)
361
- domain.to_s =~ /^(.*)\.(#{parts.join('\.')})$/
361
+ domain.to_s.chomp(".") =~ /^(.*)\.(#{parts.join('\.')})$/
362
362
  [$1, $2]
363
363
  end
364
364
 
@@ -185,6 +185,8 @@ module PublicSuffixService
185
185
  # which directly match the labels of the prevailing rule (joined by dots).
186
186
  # * The registered domain is the public suffix plus one additional label.
187
187
  #
188
+ # @param [String, #to_s] domain The domain name.
189
+ #
188
190
  # @return [PublicSuffixService::Rule::*, nil]
189
191
  def find(domain)
190
192
  rules = select(domain)
@@ -18,7 +18,7 @@ module PublicSuffixService
18
18
 
19
19
  module Version
20
20
  MAJOR = 0
21
- MINOR = 7
21
+ MINOR = 8
22
22
  PATCH = 0
23
23
  BUILD = nil
24
24
 
@@ -34,17 +34,25 @@ module PublicSuffixService
34
34
  # Parsing uses the default {PublicSuffixService::RuleList}.
35
35
  #
36
36
  # @param [String, #to_s] domain
37
- # The domain name to parse.
37
+ # The domain name or fully qualified domain name to parse.
38
38
  #
39
39
  # @return [PublicSuffixService::Domain]
40
40
  #
41
41
  # @example Parse a valid domain
42
42
  # PublicSuffixService.parse("google.com")
43
43
  # # => #<PubliSuffixService::Domain ...>
44
- #
44
+ #
45
45
  # @example Parse a valid subdomain
46
46
  # PublicSuffixService.parse("www.google.com")
47
47
  # # => #<PubliSuffixService::Domain ...>
48
+ #
49
+ # @example Parse a fully qualified domain
50
+ # PublicSuffixService.parse("google.com.")
51
+ # # => #<PubliSuffixService::Domain ...>
52
+ #
53
+ # @example Parse a fully qualified domain (subdomain)
54
+ # PublicSuffixService.parse("www.google.com.")
55
+ # # => #<PubliSuffixService::Domain ...>
48
56
  #
49
57
  # @example Parse an invalid domain
50
58
  # PublicSuffixService.parse("x.yz")
@@ -63,7 +71,7 @@ module PublicSuffixService
63
71
  def self.parse(domain)
64
72
  rule = RuleList.default.find(domain)
65
73
  if rule.nil?
66
- raise(DomainInvalid, "`#{domain}' is not a valid domain")
74
+ raise DomainInvalid, "`#{domain}' is not a valid domain"
67
75
  end
68
76
  if !rule.allow?(domain)
69
77
  raise DomainNotAllowed, "`#{domain}' is not allowed according to Registry policy"
@@ -86,30 +94,36 @@ module PublicSuffixService
86
94
  # without actually parsing it.
87
95
  #
88
96
  # This method doesn't care whether domain is a domain or subdomain.
89
- # The check is performed using the default {PublicSuffixService::RuleList}.
97
+ # The validation is performed using the default {PublicSuffixService::RuleList}.
90
98
  #
91
99
  # @param [String, #to_s] domain
92
- # The domain name to check.
100
+ # The domain name or fully qualified domain name to validate.
93
101
  #
94
102
  # @return [Boolean]
95
103
  #
96
- # @example Check a valid domain
104
+ # @example Validate a valid domain
97
105
  # PublicSuffixService.valid?("example.com")
98
106
  # # => true
99
107
  #
100
- # @example Check a valid subdomain
108
+ # @example Validate a valid subdomain
101
109
  # PublicSuffixService.valid?("www.example.com")
102
110
  # # => true
103
111
  #
104
- # @example Check a not-assigned domain
112
+ # @example Validate a not-assigned domain
105
113
  # PublicSuffixService.valid?("example.zip")
106
114
  # # => false
107
115
  #
108
- # @example Check a not-allowed domain
116
+ # @example Validate a not-allowed domain
109
117
  # PublicSuffixService.valid?("example.do")
110
118
  # # => false
111
119
  # PublicSuffixService.valid?("www.example.do")
112
120
  # # => true
121
+ #
122
+ # @example Validate a fully qualified domain
123
+ # PublicSuffixService.valid?("google.com.")
124
+ # # => true
125
+ # PublicSuffixService.valid?("www.google.com.")
126
+ # # => true
113
127
  #
114
128
  # @example Check an URL (which is not a valid domain)
115
129
  # PublicSuffixService.valid?("http://www.example.com")
@@ -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.6.0"
5
+ s.version = "0.7.0"
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-18}
9
+ s.date = %q{2010-10-09}
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}
@@ -23,11 +23,11 @@ Gem::Specification.new do |s|
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<mocha>, [">= 0"])
26
+ s.add_development_dependency(%q<rr>, [">= 0"])
27
27
  else
28
- s.add_dependency(%q<mocha>, [">= 0"])
28
+ s.add_dependency(%q<rr>, [">= 0"])
29
29
  end
30
30
  else
31
- s.add_dependency(%q<mocha>, [">= 0"])
31
+ s.add_dependency(%q<rr>, [">= 0"])
32
32
  end
33
33
  end
@@ -6,9 +6,26 @@ class PublicSuffixService::DomainTest < Test::Unit::TestCase
6
6
  @klass = PublicSuffixService::Domain
7
7
  end
8
8
 
9
- def test_domain_to_lables
10
- assert_equal %w{com live spaces someone}, PublicSuffixService::Domain.domain_to_labels('someone.spaces.live.com')
11
- assert_equal %w{com zoho wiki leontina23samiko}, PublicSuffixService::Domain.domain_to_labels('leontina23samiko.wiki.zoho.com')
9
+ # Tokenizes given input into labels.
10
+ def test_self_domain_to_labels
11
+ assert_equal %w( com live spaces someone ),
12
+ PublicSuffixService::Domain.domain_to_labels("someone.spaces.live.com")
13
+ assert_equal %w( com zoho wiki leontina23samiko ),
14
+ PublicSuffixService::Domain.domain_to_labels("leontina23samiko.wiki.zoho.com")
15
+ end
16
+
17
+ # Converts input into String.
18
+ def test_self_domain_to_labels_converts_input_to_string
19
+ assert_equal %w( com live spaces someone ),
20
+ PublicSuffixService::Domain.domain_to_labels(:"someone.spaces.live.com")
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
+ PublicSuffixService::Domain.domain_to_labels("someone.spaces.live.com")
27
+ assert_equal %w( com live spaces someone ),
28
+ PublicSuffixService::Domain.domain_to_labels(:"someone.spaces.live.com")
12
29
  end
13
30
 
14
31
 
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ class ErrorsTest < Test::Unit::TestCase
4
+
5
+ # Inherits from StandardError
6
+ def test_error_inheritance
7
+ assert_kind_of StandardError,
8
+ PublicSuffixService::Error.new
9
+ end
10
+
11
+ # Inherits from PublicSuffixService::Error
12
+ def test_domain_invalid_inheritance
13
+ assert_kind_of PublicSuffixService::Error,
14
+ PublicSuffixService::DomainInvalid.new
15
+ end
16
+
17
+ # Inherits from PublicSuffixService::DomainInvalid
18
+ def test_domain_not_allowed_inheritance
19
+ assert_kind_of PublicSuffixService::DomainInvalid,
20
+ PublicSuffixService::DomainNotAllowed.new
21
+ end
22
+
23
+ end
@@ -63,9 +63,11 @@ class PublicSuffixService::RuleBaseTest < Test::Unit::TestCase
63
63
  assert @klass.new("uk").match?("example.uk")
64
64
  assert !@klass.new("gk").match?("example.uk")
65
65
  assert !@klass.new("example").match?("example.uk")
66
+
66
67
  assert @klass.new("uk").match?("example.co.uk")
67
68
  assert !@klass.new("gk").match?("example.co.uk")
68
69
  assert !@klass.new("co").match?("example.co.uk")
70
+
69
71
  assert @klass.new("co.uk").match?("example.co.uk")
70
72
  assert !@klass.new("uk.co").match?("example.co.uk")
71
73
  assert !@klass.new("go.uk").match?("example.co.uk")
@@ -107,20 +109,34 @@ class PublicSuffixService::RuleNormalTest < Test::Unit::TestCase
107
109
  assert @klass.new("uk").match?("example.uk")
108
110
  assert !@klass.new("gk").match?("example.uk")
109
111
  assert !@klass.new("example").match?("example.uk")
112
+
110
113
  assert @klass.new("uk").match?("example.co.uk")
111
114
  assert !@klass.new("gk").match?("example.co.uk")
112
115
  assert !@klass.new("co").match?("example.co.uk")
116
+
113
117
  assert @klass.new("co.uk").match?("example.co.uk")
114
118
  assert !@klass.new("uk.co").match?("example.co.uk")
115
119
  assert !@klass.new("go.uk").match?("example.co.uk")
116
120
  end
117
121
 
122
+ def test_match_with_fully_qualified_domain_name
123
+ assert @klass.new("com").match?("com.")
124
+ assert @klass.new("com").match?("example.com.")
125
+ assert @klass.new("com").match?("www.example.com.")
126
+ end
127
+
118
128
  def test_allow
119
129
  assert !@klass.new("com").allow?("com")
120
130
  assert @klass.new("com").allow?("example.com")
121
131
  assert @klass.new("com").allow?("www.example.com")
122
132
  end
123
133
 
134
+ def test_allow_with_fully_qualified_domain_name
135
+ assert !@klass.new("com").allow?("com.")
136
+ assert @klass.new("com").allow?("example.com.")
137
+ assert @klass.new("com").allow?("www.example.com.")
138
+ end
139
+
124
140
 
125
141
  def test_length
126
142
  assert_equal 1, @klass.new("com").length
@@ -135,8 +151,15 @@ class PublicSuffixService::RuleNormalTest < Test::Unit::TestCase
135
151
  end
136
152
 
137
153
  def test_decompose
138
- assert_equal %w(example com), @klass.new("com").decompose("example.com")
139
- assert_equal %w(foo.example com), @klass.new("com").decompose("foo.example.com")
154
+ assert_equal [nil, nil], @klass.new("com").decompose("com")
155
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com")
156
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com")
157
+ end
158
+
159
+ def test_decompose_with_fully_qualified_domain_name
160
+ assert_equal [nil, nil], @klass.new("com").decompose("com.")
161
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com.")
162
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com.")
140
163
  end
141
164
 
142
165
  end
@@ -168,6 +191,25 @@ class PublicSuffixService::RuleExceptionTest < Test::Unit::TestCase
168
191
  assert !@klass.new("!british-library.uk").match?("example.co.uk")
169
192
  end
170
193
 
194
+ def test_match_with_fully_qualified_domain_name
195
+ assert @klass.new("!uk").match?("uk.")
196
+ assert @klass.new("!uk").match?("co.uk.")
197
+ assert @klass.new("!uk").match?("example.co.uk.")
198
+ assert @klass.new("!uk").match?("www.example.co.uk.")
199
+ end
200
+
201
+ def test_allow
202
+ assert !@klass.new("!british-library.uk").allow?("uk")
203
+ assert @klass.new("!british-library.uk").allow?("british-library.uk")
204
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk")
205
+ end
206
+
207
+ def test_allow_with_fully_qualified_domain_name
208
+ assert !@klass.new("!british-library.uk").allow?("uk.")
209
+ assert @klass.new("!british-library.uk").allow?("british-library.uk.")
210
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk.")
211
+ end
212
+
171
213
 
172
214
  def test_length
173
215
  assert_equal 1, @klass.new("!british-library.uk").length
@@ -175,13 +217,20 @@ class PublicSuffixService::RuleExceptionTest < Test::Unit::TestCase
175
217
  end
176
218
 
177
219
  def test_parts
178
- assert_equal %w(uk), @klass.new("!british-library.uk").parts
179
- assert_equal %w(tokyo jp), @klass.new("!metro.tokyo.jp").parts
220
+ assert_equal %w( uk ), @klass.new("!british-library.uk").parts
221
+ assert_equal %w( tokyo jp ), @klass.new("!metro.tokyo.jp").parts
180
222
  end
181
223
 
182
224
  def test_decompose
183
- assert_equal %w(british-library uk), @klass.new("!british-library.uk").decompose("british-library.uk")
184
- assert_equal %w(foo.british-library uk), @klass.new("!british-library.uk").decompose("foo.british-library.uk")
225
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk")
226
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk")
227
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk")
228
+ end
229
+
230
+ def test_decompose_with_fully_qualified_domain_name
231
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk.")
232
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk.")
233
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk.")
185
234
  end
186
235
 
187
236
  end
@@ -211,10 +260,25 @@ class PublicSuffixService::RuleWildcardTest < Test::Unit::TestCase
211
260
  assert !@klass.new("*.go.uk").match?("example.co.uk")
212
261
  end
213
262
 
263
+ def test_match_with_fully_qualified_domain_name
264
+ assert @klass.new("*.uk").match?("uk.")
265
+ assert @klass.new("*.uk").match?("co.uk.")
266
+ assert @klass.new("*.uk").match?("example.co.uk.")
267
+ assert @klass.new("*.uk").match?("www.example.co.uk.")
268
+ end
269
+
214
270
  def test_allow
215
- assert !@klass.new("*.com").allow?("com")
216
- assert !@klass.new("*.com").allow?("example.com")
217
- assert @klass.new("*.com").allow?("www.example.com")
271
+ assert !@klass.new("*.uk").allow?("uk")
272
+ assert !@klass.new("*.uk").allow?("co.uk")
273
+ assert @klass.new("*.uk").allow?("example.co.uk")
274
+ assert @klass.new("*.uk").allow?("www.example.co.uk")
275
+ end
276
+
277
+ def test_allow_with_fully_qualified_domain_name
278
+ assert !@klass.new("*.uk").allow?("uk.")
279
+ assert !@klass.new("*.uk").allow?("co.uk.")
280
+ assert @klass.new("*.uk").allow?("example.co.uk.")
281
+ assert @klass.new("*.uk").allow?("www.example.co.uk.")
218
282
  end
219
283
 
220
284
 
@@ -224,14 +288,20 @@ class PublicSuffixService::RuleWildcardTest < Test::Unit::TestCase
224
288
  end
225
289
 
226
290
  def test_parts
227
- assert_equal %w(uk), @klass.new("*.uk").parts
228
- assert_equal %w(co uk), @klass.new("*.co.uk").parts
291
+ assert_equal %w( uk ), @klass.new("*.uk").parts
292
+ assert_equal %w( co uk ), @klass.new("*.co.uk").parts
229
293
  end
230
294
 
231
295
  def test_decompose
232
296
  assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do")
233
- assert_equal %w(google co.uk), @klass.new("*.uk").decompose("google.co.uk")
234
- assert_equal %w(foo.google co.uk), @klass.new("*.uk").decompose("foo.google.co.uk")
297
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk")
298
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk")
299
+ end
300
+
301
+ def test_decompose_with_fully_qualified_domain_name
302
+ assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do.")
303
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk.")
304
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk.")
235
305
  end
236
306
 
237
307
  end
@@ -44,6 +44,14 @@ class PublicSuffixServiceTest < Test::Unit::TestCase
44
44
  assert_equal "one.two", domain.trd
45
45
  end
46
46
 
47
+ def test_self_parse_a_fully_qualified_domain_name
48
+ domain = PublicSuffixService.parse("www.example.com.")
49
+ assert_instance_of PublicSuffixService::Domain, domain
50
+ assert_equal "com", domain.tld
51
+ assert_equal "example", domain.sld
52
+ assert_equal "www", domain.trd
53
+ end
54
+
47
55
  def test_self_parse_should_raise_with_invalid_domain
48
56
  error = assert_raise(PublicSuffixService::DomainInvalid) { PublicSuffixService.parse("example.zip") }
49
57
  assert_match %r{example\.zip}, error.message
@@ -55,13 +63,23 @@ class PublicSuffixServiceTest < Test::Unit::TestCase
55
63
  end
56
64
 
57
65
 
58
- def test_self_valid_question
66
+ def test_self_valid
59
67
  assert PublicSuffixService.valid?("google.com")
60
68
  assert PublicSuffixService.valid?("www.google.com")
61
69
  assert PublicSuffixService.valid?("google.co.uk")
62
70
  assert PublicSuffixService.valid?("www.google.co.uk")
71
+ end
72
+
73
+ # Returns false when domain has an invalid TLD
74
+ def test_self_valid_with_invalid_tld
63
75
  assert !PublicSuffixService.valid?("google.zip")
64
76
  assert !PublicSuffixService.valid?("www.google.zip")
65
77
  end
66
78
 
79
+ def test_self_valid_with_fully_qualified_domain_name
80
+ assert PublicSuffixService.valid?("google.com.")
81
+ assert PublicSuffixService.valid?("google.co.uk.")
82
+ assert !PublicSuffixService.valid?("google.zip.")
83
+ end
84
+
67
85
  end
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: 3
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
8
+ - 8
9
9
  - 0
10
- version: 0.7.0
10
+ version: 0.8.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-10-09 00:00:00 +02:00
18
+ date: 2010-12-05 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - public_suffix_service.gemspec
51
51
  - test/acceptance_test.rb
52
52
  - test/public_suffix_service/domain_test.rb
53
+ - test/public_suffix_service/errors_test.rb
53
54
  - test/public_suffix_service/rule_list_test.rb
54
55
  - test/public_suffix_service/rule_test.rb
55
56
  - test/public_suffix_service_test.rb