better blacklist support through regex

This commit is contained in:
Ben Balter 2014-04-01 15:15:28 -04:00
parent 3976b2057b
commit a81a7b4574
2 changed files with 3 additions and 3 deletions

View File

@ -125,7 +125,7 @@ module Swot
# These are domains that snuck into the edu registry,
# but don't pass the education sniff test
# Note: domain must be a direct match
# Note: validated domain must not end with the blacklisted string
BLACKLIST = [
'si.edu',
]
@ -142,7 +142,7 @@ module Swot
domain = get_domain(text)
return false if domain.nil?
if BLACKLIST.include? domain.name
if BLACKLIST.any? { |d| domain.name =~ /#{Regexp.escape(d)}$/ }
false
elsif ACADEMIC_TLDS[domain.tld]
true

View File

@ -60,7 +60,7 @@ class TestEmail < Test::Unit::TestCase
end
should "fail blacklisted domains" do
["si.edu", " si.edu ", "imposter@si.edu"].each do |domain|
["si.edu", " si.edu ", "imposter@si.edu", "foo.si.edu"].each do |domain|
assert_equal false, Swot::is_academic?(domain), "#{domain} should be denied"
end
end