From 386dbbb3a62ac9f499fa56bf22f9283315c85a3b Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 31 Mar 2021 17:51:09 +0200 Subject: [PATCH] Fix path issue when fetching favicon for resources Signed-off-by: Thomas Citharel --- lib/service/rich_media/favicon.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/service/rich_media/favicon.ex b/lib/service/rich_media/favicon.ex index 12768b2d..ddbbb269 100644 --- a/lib/service/rich_media/favicon.ex +++ b/lib/service/rich_media/favicon.ex @@ -60,12 +60,16 @@ defmodule Mobilizon.Service.RichMedia.Favicon do uri = URI.parse(url) cond do - is_nil(image_uri.host) -> "#{uri.scheme}://#{uri.host}#{path}" + is_nil(image_uri.host) -> "#{uri.scheme}://#{uri.host}#{correct_path(path)}" is_nil(image_uri.scheme) -> "#{uri.scheme}:#{path}" true -> path end end + # Sometimes paths have "/" in front, sometimes not + defp correct_path("/" <> _ = path), do: path + defp correct_path(path), do: "/#{path}" + @spec find_favicon_link_tag(String.t()) :: {:ok, tuple()} | {:error, any()} defp find_favicon_link_tag(html) do with {:ok, html} <- Floki.parse_document(html),