Fix path issue when fetching favicon for resources

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-31 17:51:09 +02:00
parent c4f8fe0fe8
commit 386dbbb3a6
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 5 additions and 1 deletions

View File

@ -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),