diff --git a/changelog.d/attachment-zero-size.fix b/changelog.d/attachment-zero-size.fix new file mode 100644 index 000000000..dc42677c4 --- /dev/null +++ b/changelog.d/attachment-zero-size.fix @@ -0,0 +1 @@ +Do not crash when rendering attachments with zero width or height diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index f7b815ed7..1a0d7a3ce 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -597,6 +597,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do end describe "attachments" do + test "skips meta for zero dimensions" do + for {width, height} <- [{0, 0}, {200, 0}, {0, 100}] do + object = %{ + "type" => "Image", + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "someurl", + "width" => width, + "height" => height + } + ] + } + + refute Map.has_key?(StatusView.render("attachment.json", %{attachment: object}), :meta) + end + end + test "Complete Mastodon style" do object = %{ "type" => "Image",