diff --git a/.gitignore b/.gitignore index 6e69fb10a8..fb55aef28a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store Gemfile.lock +*.gem diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000..227cea2156 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.0.0 diff --git a/lib/swot.rb b/lib/swot.rb index b2a9d0bd89..b00efb3975 100644 --- a/lib/swot.rb +++ b/lib/swot.rb @@ -123,6 +123,13 @@ module Swot 'vic.edu.au' => 1, } + # These are domains that snuck into the edu registry, + # but don't pass the education sniff test + # Note: domain must be a direct match + BLACKLIST = [ + 'si.edu', + ] + class << self # Figure out if an email or domain belongs to academic institution. @@ -135,7 +142,9 @@ module Swot domain = get_domain(text) return false if domain.nil? - if ACADEMIC_TLDS[domain.tld] + if BLACKLIST.include? domain.name + false + elsif ACADEMIC_TLDS[domain.tld] true elsif match_academic_domain?(domain) true diff --git a/swot.gemspec b/swot.gemspec index fe46dc885b..61d2519bbc 100644 --- a/swot.gemspec +++ b/swot.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| ] s.files = [ ".document", - ".rbenv-version", + ".ruby-version", "CONTRIBUTING.md", "Gemfile", "LICENSE.txt", @@ -7725,4 +7725,3 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 1.8.3"]) end end - diff --git a/test/test_swot.rb b/test/test_swot.rb index bda0007f52..8f8872087c 100644 --- a/test/test_swot.rb +++ b/test/test_swot.rb @@ -58,4 +58,10 @@ class TestEmail < Test::Unit::TestCase assert_equal Swot::academic?('stanford.edu'), true assert_equal Swot::school_name('lreilly@cs.strath.ac.uk'), "University of Strathclyde" end + + should "fail blacklisted domains" do + ["si.edu", " si.edu ", "imposter@si.edu"].each do |domain| + assert_equal false, Swot::is_academic?(domain), "#{domain} should be denied" + end + end end