From a81a7b4574d64a101d61496607fc1878dee4209e Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Tue, 1 Apr 2014 15:15:28 -0400 Subject: [PATCH] better blacklist support through regex --- lib/swot.rb | 4 ++-- test/test_swot.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/swot.rb b/lib/swot.rb index 5c99ee0bfd..b503298354 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 =~ /#{Regexp.escape(d)}$/ } false elsif ACADEMIC_TLDS[domain.tld] true diff --git a/test/test_swot.rb b/test/test_swot.rb index 8f8872087c..e95c0d7819 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