Workaround for URI.merge/2 bug https://github.com/elixir-lang/elixir/issues/10771
authorMark Felder <feld@feld.me>
Sat, 6 Mar 2021 18:02:32 +0000 (12:02 -0600)
committerMark Felder <feld@feld.me>
Wed, 10 Mar 2021 23:15:31 +0000 (17:15 -0600)
If we avoid URI.merge unless we know we need it we reduce the edge cases we could encounter.
The site would need to both have "//" in the %URI{:path} and the image needs to be a relative URL.

lib/pleroma/web/mastodon_api/views/status_view.ex

index f3f54e03dc00cf8c927e05923e705c634abeabf6..cf8037abbb903f772e4f9c88a43b645f7a348ad6 100644 (file)
@@ -380,9 +380,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     page_url = page_url_data |> to_string
 
     image_url =
-      if is_binary(rich_media["image"]) do
-        URI.merge(page_url_data, URI.parse(rich_media["image"]))
-        |> to_string
+      cond do
+        !is_binary(rich_media["image"]) ->
+          nil
+
+        String.starts_with?(rich_media["image"], "http") ->
+          rich_media["image"]
+
+        true ->
+          URI.merge(page_url_data, URI.parse(rich_media["image"])) |> to_string
       end
 
     %{