Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Source Rendered
@@ -108,6 +108,22 @@ This library automatically recognizes Fully Qualified Domain Names. A FQDN is a
108 108 domain.tld
109 109 # => "com"
110 110
  111 +## Private domains
  112 +
  113 +This library has support for switching off support for private (non-ICANN) domains
  114 +
  115 + # Parse a domain on a private TLD
  116 + domain = PublicSuffix.parse("something.blogspot.com")
  117 + # => #<PublicSuffix::Domain>
  118 + domain.tld
  119 + # => "blogspot.com"
  120 + # Disable support for private TLDs
  121 + PublicSuffix::List.private_domains = false
  122 + # => #<PublicSuffix::List>
  123 + domain = PublicSuffix.parse("something.blogspot.com")
  124 + # => #<PublicSuffix::Domain>
  125 + domain.tld
  126 + # => "com"
111 127
112 128 ## Feedback and bug reports
113 129
19 lib/public_suffix/list.rb
@@ -67,6 +67,23 @@ def self.default=(value)
67 67 @default = value
68 68 end
69 69
  70 + # Shows if support for private (non-ICANN) domains is enabled or not
  71 + #
  72 + # @return [Boolean]
  73 + def self.private_domains?
  74 + @private_domains != false
  75 + end
  76 +
  77 + # Enables/disables support for private (non-ICANN) domains
  78 + # Implicitly reloads the list
  79 + # @param [Boolean] enable/disable support
  80 + #
  81 + # @return [PublicSuffix::List]
  82 + def self.private_domains=(value)
  83 + @private_domains = !!value
  84 + self.clear
  85 + end
  86 +
70 87 # Sets the default rule list to +nil+.
71 88 #
72 89 # @return [self]
@@ -104,7 +121,7 @@ def self.parse(input)
104 121 new do |list|
105 122 input.each_line do |line|
106 123 line.strip!
107   -
  124 + break if !private_domains? && line.include?('===BEGIN PRIVATE DOMAINS===')
108 125 # strip blank lines
109 126 if line.empty?
110 127 next
2  test/unit/list_test.rb
@@ -38,7 +38,6 @@ def test_equality_with_internals
38 38 assert_equal PublicSuffix::List.new.add(rule), PublicSuffix::List.new.add(rule)
39 39 end
40 40
41   -
42 41 def test_add
43 42 assert_equal @list, @list.add(PublicSuffix::Rule.factory(""))
44 43 assert_equal @list, @list << PublicSuffix::Rule.factory("")
@@ -133,7 +132,6 @@ def test_self_reload
133 132 assert_equal PublicSuffix::List.new, PublicSuffix::List.default
134 133 end
135 134
136   -
137 135 def test_self_parse
138 136 list = PublicSuffix::List.parse(<<EOS)
139 137 // ***** BEGIN LICENSE BLOCK *****
15 test/unit/public_suffix_test.rb
@@ -51,6 +51,21 @@ def test_self_parse_a_fully_qualified_domain_name
51 51 assert_equal "example", domain.sld
52 52 assert_equal "www", domain.trd
53 53 end
  54 +
  55 + def test_private_domains_are_enabled_by_default
  56 + domain = PublicSuffix.parse("www.example.blogspot.com")
  57 + assert_equal "blogspot.com", domain.tld
  58 + end
  59 +
  60 + def test_disable_support_for_private_domains
  61 + begin
  62 + PublicSuffix::List.private_domains = false
  63 + domain = PublicSuffix.parse("www.example.blogspot.com")
  64 + assert_equal "com", domain.tld
  65 + ensure
  66 + PublicSuffix::List.private_domains = true
  67 + end
  68 + end
54 69
55 70 def test_self_parse_a_domain_with_custom_list
56 71 list = PublicSuffix::List.new

0 comments on commit 83d008b

Please sign in to comment.
Something went wrong with that request. Please try again.