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 #26 from itspriddle/feature/parse_with_custom_list

Allow a custom List on `PublicSuffix.parse`
  • Loading branch information...
commit d2f1e77ac04befee37eb84e98adb8c5383c1f41c 2 parents 3b71f0b + 02d5883
Simone Carletti authored

Showing 2 changed files with 14 additions and 4 deletions. Show diff stats Hide diff stats

  1. +4 4 lib/public_suffix.rb
  2. +10 0 test/unit/public_suffix_test.rb
8 lib/public_suffix.rb
@@ -24,10 +24,10 @@ module PublicSuffix
24 24 # Parses +domain+ and returns the
25 25 # {PublicSuffix::Domain} instance.
26 26 #
27   - # Parsing uses the default {PublicSuffix::List}.
28   - #
29 27 # @param [String, #to_s] domain
30 28 # The domain name or fully qualified domain name to parse.
  29 + # @param [PublicSuffix::List] list
  30 + # The rule list to search, defaults to the default {PublicSuffix::List}
31 31 #
32 32 # @return [PublicSuffix::Domain]
33 33 #
@@ -61,8 +61,8 @@ module PublicSuffix
61 61 # If a rule for +domain+ is found, but the rule
62 62 # doesn't allow +domain+.
63 63 #
64   - def self.parse(domain)
65   - rule = List.default.find(domain)
  64 + def self.parse(domain, list = List.default)
  65 + rule = list.find(domain)
66 66
67 67 if rule.nil?
68 68 raise DomainInvalid, "`#{domain}' is not a valid domain"
10 test/unit/public_suffix_test.rb
@@ -52,6 +52,16 @@ def test_self_parse_a_fully_qualified_domain_name
52 52 assert_equal "www", domain.trd
53 53 end
54 54
  55 + def test_self_parse_a_domain_with_custom_list
  56 + list = PublicSuffix::List.new
  57 + list << PublicSuffix::Rule.factory("test")
  58 +
  59 + domain = PublicSuffix.parse("www.example.test", list)
  60 + assert_equal "test", domain.tld
  61 + assert_equal "example", domain.sld
  62 + assert_equal "www", domain.trd
  63 + end
  64 +
55 65 def test_self_parse_raises_with_invalid_domain
56 66 error = assert_raise(PublicSuffix::DomainInvalid) { PublicSuffix.parse("example.zip") }
57 67 assert_match %r{example\.zip}, error.message

0 comments on commit d2f1e77

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