Merge pull request 'StatusView: handle attachments with zero width or height' (#8026) from lambadalambda/pleroma:fix/attachment-zero-size into develop
Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/8026
This commit is contained in:
commit
d54ff52691
3 changed files with 20 additions and 1 deletions
1
changelog.d/attachment-zero-size.fix
Normal file
1
changelog.d/attachment-zero-size.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Do not crash when rendering attachments with zero width or height
|
||||||
|
|
@ -675,7 +675,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
def render("attachment_meta.json", %{
|
def render("attachment_meta.json", %{
|
||||||
attachment: %{"url" => [%{"width" => width, "height" => height} | _]}
|
attachment: %{"url" => [%{"width" => width, "height" => height} | _]}
|
||||||
})
|
})
|
||||||
when is_integer(width) and is_integer(height) do
|
when is_integer(width) and is_integer(height) and width > 0 and height > 0 do
|
||||||
%{
|
%{
|
||||||
original: %{
|
original: %{
|
||||||
width: width,
|
width: width,
|
||||||
|
|
|
||||||
|
|
@ -597,6 +597,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "attachments" do
|
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
|
test "Complete Mastodon style" do
|
||||||
object = %{
|
object = %{
|
||||||
"type" => "Image",
|
"type" => "Image",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue