Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #28 from rb2k/master

Add support for disabling private/non-icann domains
  • Loading branch information...
commit 83d008b5917fa7decb90aa263d108c92e5dc2ef8 2 parents 2a6efa1 + f2e772a
Simone Carletti authored
16 README.md
View
@@ -108,6 +108,22 @@ This library automatically recognizes Fully Qualified Domain Names. A FQDN is a
domain.tld
# => "com"
+## Private domains
+
+This library has support for switching off support for private (non-ICANN) domains
+
+ # Parse a domain on a private TLD
+ domain = PublicSuffix.parse("something.blogspot.com")
+ # => #<PublicSuffix::Domain>
+ domain.tld
+ # => "blogspot.com"
+ # Disable support for private TLDs
+ PublicSuffix::List.private_domains = false
+ # => #<PublicSuffix::List>
+ domain = PublicSuffix.parse("something.blogspot.com")
+ # => #<PublicSuffix::Domain>
+ domain.tld
+ # => "com"
## Feedback and bug reports
19 lib/public_suffix/list.rb
View
@@ -67,6 +67,23 @@ def self.default=(value)
@default = value
end
+ # Shows if support for private (non-ICANN) domains is enabled or not
+ #
+ # @return [Boolean]
+ def self.private_domains?
+ @private_domains != false
+ end
+
+ # Enables/disables support for private (non-ICANN) domains
+ # Implicitly reloads the list
+ # @param [Boolean] enable/disable support
+ #
+ # @return [PublicSuffix::List]
+ def self.private_domains=(value)
+ @private_domains = !!value
+ self.clear
+ end
+
# Sets the default rule list to +nil+.
#
# @return [self]
@@ -104,7 +121,7 @@ def self.parse(input)
new do |list|
input.each_line do |line|
line.strip!
-
+ break if !private_domains? && line.include?('===BEGIN PRIVATE DOMAINS===')
# strip blank lines
if line.empty?
next
2  test/unit/list_test.rb
View
@@ -38,7 +38,6 @@ def test_equality_with_internals
assert_equal PublicSuffix::List.new.add(rule), PublicSuffix::List.new.add(rule)
end
-
def test_add
assert_equal @list, @list.add(PublicSuffix::Rule.factory(""))
assert_equal @list, @list << PublicSuffix::Rule.factory("")
@@ -133,7 +132,6 @@ def test_self_reload
assert_equal PublicSuffix::List.new, PublicSuffix::List.default
end
-
def test_self_parse
list = PublicSuffix::List.parse(<<EOS)
// ***** BEGIN LICENSE BLOCK *****
15 test/unit/public_suffix_test.rb
View
@@ -51,6 +51,21 @@ def test_self_parse_a_fully_qualified_domain_name
assert_equal "example", domain.sld
assert_equal "www", domain.trd
end
+
+ def test_private_domains_are_enabled_by_default
+ domain = PublicSuffix.parse("www.example.blogspot.com")
+ assert_equal "blogspot.com", domain.tld
+ end
+
+ def test_disable_support_for_private_domains
+ begin
+ PublicSuffix::List.private_domains = false
+ domain = PublicSuffix.parse("www.example.blogspot.com")
+ assert_equal "com", domain.tld
+ ensure
+ PublicSuffix::List.private_domains = true
+ end
+ end
def test_self_parse_a_domain_with_custom_list
list = PublicSuffix::List.new
Please sign in to comment.
Something went wrong with that request. Please try again.