Don't save double tags in AP objects we create
authorlain <lain@soykaf.club>
Wed, 23 May 2018 15:25:24 +0000 (17:25 +0200)
committerlain <lain@soykaf.club>
Wed, 23 May 2018 15:25:24 +0000 (17:25 +0200)
This crashed Mastodon workers.

lib/pleroma/web/common_api/utils.ex
test/web/common_api/common_api_test.exs [new file with mode: 0644]

index e774743a2736c41d1410e1ada51088b296237506..71412eea851e37f64c8d14df53bc0f3b60f5e024 100644 (file)
@@ -133,7 +133,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       "context" => context,
       "attachment" => attachments,
       "actor" => actor,
-      "tag" => tags |> Enum.map(fn {_, tag} -> tag end)
+      "tag" => tags |> Enum.map(fn {_, tag} -> tag end) |> Enum.uniq()
     }
 
     if inReplyTo do
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
new file mode 100644 (file)
index 0000000..b597e6e
--- /dev/null
@@ -0,0 +1,13 @@
+defmodule Pleroma.Web.CommonAPI.UtilsTest do
+  use Pleroma.DataCase
+  alias Pleroma.Web.CommonAPI
+
+  import Pleroma.Factory
+
+  test "it de-duplicates tags" do
+    user = insert(:user)
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
+
+    assert activity.data["object"]["tag"] == ["2hu"]
+  end
+end