diff --git a/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex b/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex index dc071cbfcd..6a971f27e0 100644 --- a/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex +++ b/lib/pleroma/ecto_type/activity_pub/object_validators/map_of_string.ex @@ -22,7 +22,11 @@ def cast(object) when is_map(object) do acc end) - {:ok, data} + if data == %{} do + {:ok, nil} + else + {:ok, data} + end end def cast(_), do: :error diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index c5871d2fc9..63192aefe0 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -345,7 +345,8 @@ def fix_tag(object), do: object def fix_content_map(%{"content" => content} = object) when not_empty_string(content), do: object # content map usually only has one language so this will do for now. - def fix_content_map(%{"contentMap" => content_map} = object) do + def fix_content_map(%{"contentMap" => content_map} = object) + when is_map(content_map) and content_map != %{} do content_groups = Map.to_list(content_map) {_, content} = Enum.at(content_groups, 0) diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index dedd389511..f92f95c6e0 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -62,6 +62,21 @@ test "Note with contentMap and summaryMap", %{note: note} do } } = ArticleNotePageValidator.cast_and_validate(note) end + + test "Note with empty *Map", %{note: note} do + note = + note + |> Map.put("summaryMap", %{"und" => "mew"}) + |> Map.put("contentMap", %{}) + + assert %{ + valid?: true, + changes: changes + } = ArticleNotePageValidator.cast_and_validate(note) + + assert Map.has_key?(changes, :summaryMap) + refute Map.has_key?(changes, :contentMap) + end end describe "Note with history" do