Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…(closes GH-20)
  • Loading branch information...
commit b4c8f7feac2e37b112c029890e93f1b5982863d5 1 parent b449cbc
@weppos authored
View
2  CHANGELOG.md
@@ -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.
View
2  lib/public_suffix/list.rb
@@ -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
13 test/acceptance_test.rb
@@ -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
9 test/unit/list_test.rb
@@ -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 }
Please sign in to comment.
Something went wrong with that request. Please try again.