From 283035ad4f9da126dae4205645662f3c83e6678a Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 27 Oct 2026 17:27:41 +0400 Subject: [PATCH] test(status_view): cover attachments with zero dimensions --- changelog.d/attachment-zero-size.fix | 1 + .../mastodon_api/views/status_view_test.exs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 changelog.d/attachment-zero-size.fix 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",