From 2e140a560702909aaf7e400660af0f7d6f1f1f3f Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:59:19 +0100 Subject: [PATCH] [Posts] Use addressable for source parsing Fixes no icons for links with square brackets --- app/helpers/link_helper.rb | 4 ++-- test/helpers/link_helper_test.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) 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