Fix Pleroma.HTML.extract_first_external_url/2
authorEgor Kislitsyn <egor@kislitsyn.com>
Fri, 29 Nov 2019 08:49:35 +0000 (15:49 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Fri, 29 Nov 2019 08:49:35 +0000 (15:49 +0700)
lib/pleroma/html.ex
test/html_test.exs

index 997e965f0829afdf4e475a1ecdc16e5f8a9e80b9..4acd46253362119ec737f79f8772ba7dba1d3c76 100644 (file)
@@ -91,6 +91,7 @@ defmodule Pleroma.HTML do
     Cachex.fetch!(:scrubber_cache, key, fn _key ->
       result =
         content
+        |> HtmlEntities.decode()
         |> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]")
         |> Floki.attribute("a", "href")
         |> Enum.at(0)
index f0869534cdced6047d9ba72be9f1b27c3a00961b..c918dbe203156a9bac79d251b94d9ab5b95c9ce7 100644 (file)
@@ -228,5 +228,16 @@ defmodule Pleroma.HTMLTest do
 
       assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
     end
+
+    test "does not crash when there is an HTML entity in a link" do
+      user = insert(:user)
+
+      {:ok, activity} =
+        CommonAPI.post(user, %{"status" => "\"http://cofe.com/?boomer=ok&foo=bar\""})
+
+      object = Object.normalize(activity)
+
+      assert {:ok, nil} = HTML.extract_first_external_url(object, object.data["content"])
+    end
   end
 end