utils: Fix maybe_splice_recipient when "object" isn’t a map
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 26 Nov 2020 23:25:24 +0000 (00:25 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Mon, 5 Apr 2021 17:19:12 +0000 (19:19 +0200)
lib/pleroma/maps.ex
lib/pleroma/web/activity_pub/utils.ex
test/pleroma/web/activity_pub/activity_pub_controller_test.exs

index 0d2e94248d079c0f45a868d2345589ca7405ff95..b08b83305ca9154129c8e9ca45cbddff5301cf9f 100644 (file)
@@ -12,4 +12,10 @@ defmodule Pleroma.Maps do
       _ -> map
     end
   end
+
+  def safe_put_in(data, keys, value) when is_map(data) and is_list(keys) do
+    Kernel.put_in(data, keys, value)
+  rescue
+    _ -> data
+  end
 end
index e81623d833817cd5bb9c8c5bc2cd9ece92b401f1..0d1a6d0f13c10fcc1ac78125f27f561eb2b0961a 100644 (file)
@@ -96,11 +96,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
         !label_in_collection?(ap_id, params["cc"])
 
     if need_splice? do
-      cc_list = extract_list(params["cc"])
+      cc = [ap_id | extract_list(params["cc"])]
 
       params
-      |> Map.put("cc", [ap_id | cc_list])
-      |> Kernel.put_in(["object", "cc"], [ap_id | cc_list])
+      |> Map.put("cc", cc)
+      |> Maps.safe_put_in(["object", "cc"], cc)
     else
       params
     end
index f6ea9e2caf609d1a25de28b8b304cf97bfbd1788..f3ce703e2426bfdb943871515c7d4dd2e63e7387 100644 (file)
@@ -1003,7 +1003,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
         "actor" => remote_actor,
         "content" => "test report",
         "id" => "https://#{remote_domain}/e3b12fd1-948c-446e-b93b-a5e67edbe1d8",
-        "nickname" => reported_user.nickname,
         "object" => [
           reported_user.ap_id,
           note.data["object"]