diff --git a/lib/swot.rb b/lib/swot.rb index bea800af4e..4aa598a18e 100644 --- a/lib/swot.rb +++ b/lib/swot.rb @@ -191,17 +191,16 @@ module Swot # # Returns a string with the FQDN; nil if there's an error. def get_domain(text) - text.strip! - return false if text.nil? - text.downcase! - text = text.split("@")[1] if text.include? "@" + PublicSuffix.parse text.downcase.match(domain_regex).captures.first + rescue + return nil + end - begin - domain = PublicSuffix.parse(text) - return domain - rescue - return nil - end + private + + # http://rubular.com/r/uW2GqSxvqD + def domain_regex + /([^@\/:]+)[:\d]*$/ end end end \ No newline at end of file diff --git a/test/test_swot.rb b/test/test_swot.rb index e2f46d47a7..46dbb0ec19 100644 --- a/test/test_swot.rb +++ b/test/test_swot.rb @@ -21,8 +21,8 @@ class TestEmail < Test::Unit::TestCase assert_equal Swot::is_academic?('stanford.edu'), true assert_equal Swot::is_academic?('slac.stanford.edu'), true assert_equal Swot::is_academic?('www.stanford.edu'), true - #assert_equal Swot::is_academic?('http://www.stanford.edu'), true - #assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true + assert_equal Swot::is_academic?('http://www.stanford.edu'), true + assert_equal Swot::is_academic?('http://www.stanford.edu:9393'), true assert_equal Swot::is_academic?('strath.ac.uk'), true assert_equal Swot::is_academic?('soft-eng.strath.ac.uk'), true assert_equal Swot::is_academic?('ugr.es'), true