Fix Pleroma.HTML.extract_first_external_url/2

This commit is contained in:
Egor Kislitsyn 2019-11-29 15:49:35 +07:00
parent d7b40dd4ba
commit a98cda7758
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
2 changed files with 12 additions and 0 deletions

View File

@ -91,6 +91,7 @@ def extract_first_external_url(object, content) do
Cachex.fetch!(:scrubber_cache, key, fn _key -> Cachex.fetch!(:scrubber_cache, key, fn _key ->
result = result =
content content
|> HtmlEntities.decode()
|> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]") |> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]")
|> Floki.attribute("a", "href") |> Floki.attribute("a", "href")
|> Enum.at(0) |> Enum.at(0)

View File

@ -228,5 +228,16 @@ test "skips microformats hashtags" do
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
end 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
end end