diff --git a/lib/swot.rb b/lib/swot.rb index 1354de66f2..d8bef27faf 100644 --- a/lib/swot.rb +++ b/lib/swot.rb @@ -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 =~ /(\A|\.)#{Regexp.escape(d)}\z/ } false elsif ACADEMIC_TLDS[domain.tld] true diff --git a/test/test_swot.rb b/test/test_swot.rb index 1f2a69546f..30e2830904 100644 --- a/test/test_swot.rb +++ b/test/test_swot.rb @@ -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