summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrinpatch <rin@patch.cx>2021-03-21 08:19:42 +0000
committerrinpatch <rin@patch.cx>2021-03-21 08:19:42 +0000
commit72143dd732263e1690605f7cbcc094913acc82e6 (patch)
treeae594fcd06b41655803ec5c81c272e019111a377
parent8f78361525e1123e82c51b541204fa9f0dba91d1 (diff)
parentb80f868c6b41d1407cf6e4f2df8913bdf7a954c0 (diff)
Merge branch 'richmedia-workaround' into 'develop'
Workaround for RichMedia preview image breakage edge case See merge request pleroma/pleroma!3363
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index d30c9fa68..3753588f2 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -381,12 +381,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
page_url = page_url_data |> to_string
- image_url =
+ image_url_data =
if is_binary(rich_media["image"]) do
- URI.merge(page_url_data, URI.parse(rich_media["image"]))
- |> to_string
+ URI.parse(rich_media["image"])
+ else
+ nil
end
+ image_url = build_image_url(image_url_data, page_url_data)
+
%{
type: "link",
provider_name: page_url_data.host,
@@ -542,4 +545,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
do: %{name: name, website: url}
defp build_application(_), do: nil
+
+ # Workaround for Elixir issue #10771
+ # Avoid applying URI.merge unless necessary
+ # TODO: revert to always attempting URI.merge(image_url_data, page_url_data)
+ # when Elixir 1.12 is the minimum supported version
+ @spec build_image_url(struct() | nil, struct()) :: String.t() | nil
+ defp build_image_url(
+ %URI{scheme: image_scheme, host: image_host} = image_url_data,
+ %URI{} = _page_url_data
+ )
+ when not is_nil(image_scheme) and not is_nil(image_host) do
+ image_url_data |> to_string
+ end
+
+ defp build_image_url(%URI{} = image_url_data, %URI{} = page_url_data) do
+ URI.merge(page_url_data, image_url_data) |> to_string
+ end
+
+ defp build_image_url(_, _), do: nil
end