excluding attachment links from RichMedia
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Mon, 29 Jun 2020 12:25:57 +0000 (15:25 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Mon, 29 Jun 2020 12:25:57 +0000 (15:25 +0300)
lib/pleroma/html.ex
test/html_test.exs

index d78c5f2025ced17c45649393954cc164841dd8d2..dc1b9b840c006694b365cfea71eb288461fc5cac 100644 (file)
@@ -109,7 +109,7 @@ defmodule Pleroma.HTML do
       result =
         content
         |> Floki.parse_fragment!()
-        |> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]")
+        |> Floki.filter_out("a.mention,a.hashtag,a.attachment,a[rel~=\"tag\"]")
         |> Floki.attribute("a", "href")
         |> Enum.at(0)
 
index 0a4b4ebbcbf23e2d87fb15e633f03df406327a58..f8907c8b4b425d44834caaff55b4936fa70d9fd3 100644 (file)
@@ -237,5 +237,19 @@ defmodule Pleroma.HTMLTest do
 
       assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
     end
+
+    test "skips attachment links" do
+      user = insert(:user)
+
+      {:ok, activity} =
+        CommonAPI.post(user, %{
+          status:
+            "<a href=\"https://pleroma.gov/media/d24caa3a498e21e0298377a9ca0149a4f4f8b767178aacf837542282e2d94fb1.png?name=image.png\" class=\"attachment\">image.png</a>"
+        })
+
+      object = Object.normalize(activity)
+
+      assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
+    end
   end
 end