Transmogrifier: Do not crash if inReplyTo does not exist and can't be fetched
authorrinpatch <rinpatch@sdf.org>
Fri, 7 Jun 2019 17:40:38 +0000 (20:40 +0300)
committerrinpatch <rinpatch@sdf.org>
Fri, 7 Jun 2019 17:40:38 +0000 (20:40 +0300)
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs

index ff031a16ee8f2ad2ac6e8ecf6b87d1fc3049cc14..3bb8b40b5c0284024ba2558950e1fee312ac965b 100644 (file)
@@ -339,7 +339,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def fix_type(%{"inReplyTo" => reply_id} = object) when is_binary(reply_id) do
     reply = Object.normalize(reply_id)
 
-    if reply.data["type"] == "Question" and object["name"] do
+    if reply && (reply.data["type"] == "Question" and object["name"]) do
       Map.put(object, "type", "Answer")
     else
       object
index 28971ae450d69ad182721ac02f2457abc297bea9..26e8d60fecf72eb6574c1684fa40bc9890fa07bf 100644 (file)
@@ -60,6 +60,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
     end
 
+    test "it does not crash if the object in inReplyTo can't be fetched" do
+      data =
+        File.read!("test/fixtures/mastodon-post-activity.json")
+        |> Poison.decode!()
+
+      object =
+        data["object"]
+        |> Map.put("inReplyTo", "https://nonexistent.space/whatever")
+
+      data =
+        data
+        |> Map.put("object", object)
+
+      {:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
+    end
+
     test "it works for incoming notices" do
       data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()