From 7651198508cc40adfab27969f196e4496bd441da Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 11 Jan 2024 07:13:13 +0100 Subject: [PATCH] Support objects with a nil contentMap (firefish) Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/3231 --- changelog.d/nil-content-map.fix | 1 + lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++++ .../transmogrifier/note_handling_test.exs | 13 +++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 changelog.d/nil-content-map.fix diff --git a/changelog.d/nil-content-map.fix b/changelog.d/nil-content-map.fix new file mode 100644 index 000000000..d4943bf74 --- /dev/null +++ b/changelog.d/nil-content-map.fix @@ -0,0 +1 @@ +Support objects with a null contentMap (firefish) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 35f3aea03..68f3e1399 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -339,6 +339,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def fix_tag(object), do: object + def fix_content_map(%{"contentMap" => nil} = object) do + Map.drop(object, ["contentMap"]) + end + # content map usually only has one language so this will do for now. def fix_content_map(%{"contentMap" => content_map} = object) do content_groups = Map.to_list(content_map) diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 9750fa25f..2507fa2b0 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -221,6 +221,19 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.NoteHandlingTest do "

@lain

" end + test "it works for incoming notices with a nil contentMap (firefish)" do + data = + File.read!("test/fixtures/mastodon-post-activity-contentmap.json") + |> Jason.decode!() + |> Map.put("contentMap", nil) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + object = Object.normalize(data["object"], fetch: false) + + assert object.data["content"] == + "

@lain

" + end + test "it works for incoming notices with to/cc not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-post-activity.json") |> Jason.decode!()