Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a custom List on PublicSuffix.parse #26

Merged
merged 1 commit into from Dec 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/public_suffix.rb
Expand Up @@ -24,10 +24,10 @@ module PublicSuffix
# Parses +domain+ and returns the
# {PublicSuffix::Domain} instance.
#
# Parsing uses the default {PublicSuffix::List}.
#
# @param [String, #to_s] domain
# The domain name or fully qualified domain name to parse.
# @param [PublicSuffix::List] list
# The rule list to search, defaults to the default {PublicSuffix::List}
#
# @return [PublicSuffix::Domain]
#
Expand Down Expand Up @@ -61,8 +61,8 @@ module PublicSuffix
# If a rule for +domain+ is found, but the rule
# doesn't allow +domain+.
#
def self.parse(domain)
rule = List.default.find(domain)
def self.parse(domain, list = List.default)
rule = list.find(domain)

if rule.nil?
raise DomainInvalid, "`#{domain}' is not a valid domain"
Expand Down
10 changes: 10 additions & 0 deletions test/unit/public_suffix_test.rb
Expand Up @@ -52,6 +52,16 @@ def test_self_parse_a_fully_qualified_domain_name
assert_equal "www", domain.trd
end

def test_self_parse_a_domain_with_custom_list
list = PublicSuffix::List.new
list << PublicSuffix::Rule.factory("test")

domain = PublicSuffix.parse("www.example.test", list)
assert_equal "test", domain.tld
assert_equal "example", domain.sld
assert_equal "www", domain.trd
end

def test_self_parse_raises_with_invalid_domain
error = assert_raise(PublicSuffix::DomainInvalid) { PublicSuffix.parse("example.zip") }
assert_match %r{example\.zip}, error.message
Expand Down