Permalink
Browse files

PublicSuffix.parse and PublicSuffix.valid? crashes when input is nil (c…

…loses GH-20)
  • Loading branch information...
weppos committed Dec 24, 2012
1 parent b449cbc commit b4c8f7feac2e37b112c029890e93f1b5982863d5
Showing with 21 additions and 5 deletions.
  1. +2 −0 CHANGELOG.md
  2. +2 −0 lib/public_suffix/list.rb
  3. +8 −5 test/acceptance_test.rb
  4. +9 −0 test/unit/list_test.rb
View
@@ -5,6 +5,8 @@
- NEW: Allow a custom List on `PublicSuffix.parse` (GH-26). [Thanks @itspriddle]
+- FIXED: PublicSuffix.parse and PublicSuffix.valid? crashes when input is nil (GH-20).
+
- CHANGED: Updated definitions.
@@ -272,6 +272,8 @@ def find(domain)
#
# @return [Array<PublicSuffix::Rule::*>]
def select(domain)
+ # raise DomainInvalid, "Blank domain"
+ return [] if domain.to_s !~ /[^[:space:]]/
# raise DomainInvalid, "`#{domain}' is not expected to contain a scheme"
return [] if domain.include?("://")
View
@@ -24,13 +24,16 @@ def test_valid
end
end
- InvalidCases = {
- "nic.ke" => PublicSuffix::DomainNotAllowed,
- "http://www.google.com" => PublicSuffix::DomainInvalid,
- }
+ InvalidCases = [
+ ["nic.ke", PublicSuffix::DomainNotAllowed],
+ ["http://www.google.com", PublicSuffix::DomainInvalid],
+ [nil, PublicSuffix::DomainInvalid],
+ ["", PublicSuffix::DomainInvalid],
+ [" ", PublicSuffix::DomainInvalid],
+ ]
def test_invalid
- InvalidCases.each do |name, error|
+ InvalidCases.each do |(name, error)|
assert_raise(error) { PublicSuffix.parse(name) }
assert !PublicSuffix.valid?(name)
end
View
@@ -95,6 +95,15 @@ def test_select_returns_empty_when_domain_has_scheme
assert_not_equal [], list.select("google.com")
end
+ def test_select_returns_empty_when_domain_is_nil
+ assert_equal [], list.select(nil)
+ end
+
+ def test_select_returns_empty_when_domain_is_blank
+ assert_equal [], list.select("")
+ assert_equal [], list.select(" ")
+ end
+
def test_self_default_getter
assert_equal nil, PublicSuffix::List.class_eval { @default }

0 comments on commit b4c8f7f

Please sign in to comment.