Merge pull request #49 from benbalter/better-blacklisting
Better blacklist support through regex
This commit is contained in:
commit
6da1bcba05
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user