commit: d9baa0980d8dabe1faf64c388acb26452cca09e9
parent c8fc821a0e9268816b4fcbb474a7299a8553a220
Author: nicole mikołajczyk <me@mkljczk.pl>
Date: Tue, 16 Dec 2025 10:49:51 +0100
Merge branch 'normalize-actor-image-hrefs' into 'develop'
Add Actor images normalization from array of urls to string
See merge request pleroma/pleroma!4404
Diffstat:
4 files changed, 84 insertions(+), 1 deletion(-)
diff --git a/changelog.d/normalize-actor-image-hrefs.fix b/changelog.d/normalize-actor-image-hrefs.fix
@@ -0,0 +1 @@
+Add Actor images normalization from array of urls to string
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1569,7 +1569,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp get_actor_url(_url), do: nil
- defp normalize_image(%{"url" => url} = data) do
+ defp normalize_image(%{"url" => url} = data) when is_binary(url) do
%{
"type" => "Image",
"url" => [%{"href" => url}]
@@ -1577,6 +1577,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> maybe_put_description(data)
end
+ defp normalize_image(%{"url" => urls}) when is_list(urls) do
+ url = urls |> List.first()
+
+ %{"url" => url}
+ |> normalize_image()
+ end
+
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
defp normalize_image(_), do: nil
diff --git a/test/fixtures/users_mock/href_as_array.json b/test/fixtures/users_mock/href_as_array.json
@@ -0,0 +1,41 @@
+{
+ "alsoKnownAs": [],
+ "attachment": [],
+ "capabilities": {},
+ "discoverable": true,
+ "endpoints": {},
+ "featured": "https://queef.in/cute_cat/collections/featured",
+ "followers": "https://queef.in/cute_cat/followers",
+ "following": "https://queef.in/cute_cat/following",
+ "icon": {
+ "type": "Image",
+ "url": [
+ "https://queef.in/storage/profile.webp",
+ "https://example.com/image"
+ ]
+ },
+ "id": "https://queef.in/cute_cat",
+ "image": {
+ "type": "Image",
+ "url": [
+ "https://queef.in/storage/banner.gif",
+ "https://example.com/image"
+ ]
+ },
+ "inbox": "https://queef.in/cute_cat/inbox",
+ "manuallyApprovesFollowers": false,
+ "name": "cute_cat",
+ "outbox": "https://queef.in/cute_cat/outbox",
+ "preferredUsername": "cute_cat",
+ "publicKey": {
+ "id": "https://queef.in/cute_cat#main-key",
+ "owner": "https://queef.in/cute_cat"
+ },
+ "published": "2025-08-18T01:16:10.000Z",
+ "summary": "A cute cat",
+ "tag": [],
+ "type": "Person",
+ "url": "https://queef.in/cute_cat",
+ "vcard:bday": null,
+ "webfinger": "acct:cute_cat@queef.in"
+}
diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs
@@ -465,6 +465,40 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ test "works with avatar/banner href as list" do
+ user_id = "https://queef.in/cute_cat"
+
+ user_data =
+ "test/fixtures/users_mock/href_as_array.json"
+ |> File.read!()
+ |> Jason.decode!()
+ |> Map.delete("featured")
+ |> Jason.encode!()
+
+ Tesla.Mock.mock(fn
+ %{
+ method: :get,
+ url: ^user_id
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: user_data,
+ headers: [{"content-type", "application/activity+json"}]
+ }
+ end)
+
+ {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
+
+ assert length(user.avatar["url"]) == 1
+ assert length(user.banner["url"]) == 1
+
+ assert user.avatar["url"] |> List.first() |> Map.fetch!("href") ==
+ "https://queef.in/storage/profile.webp"
+
+ assert user.banner["url"] |> List.first() |> Map.fetch!("href") ==
+ "https://queef.in/storage/banner.gif"
+ end
+
test "it fetches the appropriate tag-restricted posts" do
user = insert(:user)