Merge branch 'activitypub-tombstone-fix' into 'develop'
authorkaniini <nenolod@gmail.com>
Sat, 5 Jan 2019 22:29:08 +0000 (22:29 +0000)
committerkaniini <nenolod@gmail.com>
Sat, 5 Jan 2019 22:29:08 +0000 (22:29 +0000)
Don't crash on AP request for tombstone

See merge request pleroma/pleroma!630

lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/twitter_api/representers/activity_representer.ex
lib/pleroma/web/twitter_api/views/activity_view.ex
test/web/twitter_api/views/activity_view_test.exs

index e474653ff3208b4ebf1ae5f2fb9ffdd7bc9258e5..bb3c38f006f0715b8801cc79640c5b3a22c1a954 100644 (file)
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPI do
            Map.put(
              object,
              "emoji",
-             Formatter.get_emoji(status)
+             (Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"]))
              |> Enum.reduce(%{}, fn {name, file}, acc ->
                Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}")
              end)
index 2a221cc66491e629a536fcaabf244035f0e835c2..245cd52fd60eddaf7de309c7d95fd6bf10a61774 100644 (file)
@@ -207,7 +207,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "activity_type" => "post",
       "possibly_sensitive" => possibly_sensitive,
       "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
-      "summary" => object["summary"]
+      "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"])
     }
   end
 
index a0be5cfc57399fdab9fdea107686f7a9c279ec47..ad0cc76edf72adac00a899c19a7f6b052fec5e0d 100644 (file)
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "activity_type" => "post",
       "possibly_sensitive" => possibly_sensitive,
       "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
-      "summary" => summary
+      "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"])
     }
   end
 
index 013245033786af000d5be9a9d9313efdcaee3a8f..05780a54ada9e4d86793e6e76d01de7843e31948 100644 (file)
@@ -41,6 +41,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
              "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
   end
 
+  test "a create activity with a summary containing emoji" do
+    {:ok, activity} =
+      CommonAPI.post(insert(:user), %{
+        "spoiler_text" => ":woollysocks: meow",
+        "status" => "."
+      })
+
+    result = ActivityView.render("activity.json", activity: activity)
+
+    expected =
+      "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow"
+
+    assert result["summary"] == expected
+  end
+
+  test "a create activity with a summary containing invalid HTML" do
+    {:ok, activity} =
+      CommonAPI.post(insert(:user), %{
+        "spoiler_text" => "<span style=\"color: magenta; font-size: 32px;\">meow</span>",
+        "status" => "."
+      })
+
+    result = ActivityView.render("activity.json", activity: activity)
+
+    expected = "meow"
+
+    assert result["summary"] == expected
+  end
+
   test "a create activity with a note" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
@@ -73,14 +102,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "repeat_num" => 0,
       "repeated" => false,
       "statusnet_conversation_id" => convo_id,
+      "summary" => "",
       "statusnet_html" =>
         "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
       "tags" => [],
       "text" => "Hey @shp!",
       "uri" => activity.data["object"]["id"],
       "user" => UserView.render("show.json", %{user: user}),
-      "visibility" => "direct",
-      "summary" => nil
+      "visibility" => "direct"
     }
 
     assert result == expected