diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index f69feb175..99f8e8dbd 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -173,8 +173,8 @@ module LinkHelper def hostname_for_link(path) begin - uri = URI.parse(path) - rescue URI::InvalidURIError + uri = Addressable::URI.parse(path) + rescue Addressable::URI::InvalidURIError return nil end return nil unless uri.host diff --git a/test/helpers/link_helper_test.rb b/test/helpers/link_helper_test.rb index 936a1a2a4..d2e596696 100644 --- a/test/helpers/link_helper_test.rb +++ b/test/helpers/link_helper_test.rb @@ -31,6 +31,10 @@ class LinkHelperTest < ActionView::TestCase assert_equal("inkbunny.net", hostname_for_link("https://qb.ib.metapix.net")) end + test "for a link that contains square brackets" do + assert_equal("furaffinity.net", hostname_for_link("https://d.furaffinity.net/square_[brackets].png")) + end + test "it returns an image if a hostname is found" do assert_match("furaffinity.net.png", favicon_for_link("https://furaffinity.net")) end