[Posts] Use addressable for source parsing

Fixes no icons for links with square brackets
This commit is contained in:
Earlopain 2024-03-18 18:59:19 +01:00
parent aeb2076b80
commit 2e140a5607
No known key found for this signature in database
GPG Key ID: 48860312319ADF61
2 changed files with 6 additions and 2 deletions

View File

@ -173,8 +173,8 @@ module LinkHelper
def hostname_for_link(path) def hostname_for_link(path)
begin begin
uri = URI.parse(path) uri = Addressable::URI.parse(path)
rescue URI::InvalidURIError rescue Addressable::URI::InvalidURIError
return nil return nil
end end
return nil unless uri.host return nil unless uri.host

View File

@ -31,6 +31,10 @@ class LinkHelperTest < ActionView::TestCase
assert_equal("inkbunny.net", hostname_for_link("https://qb.ib.metapix.net")) assert_equal("inkbunny.net", hostname_for_link("https://qb.ib.metapix.net"))
end 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 test "it returns an image if a hostname is found" do
assert_match("furaffinity.net.png", favicon_for_link("https://furaffinity.net")) assert_match("furaffinity.net.png", favicon_for_link("https://furaffinity.net"))
end end