aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-06-19 00:31:30 +0300
committerrinpatch <rinpatch@sdf.org>2019-06-19 00:46:30 +0300
commit035368d363e31bd99efb21e1c121574718c81b5e (patch)
treee954c408cb2d6712e29f8b824ba848a8097ed6f4
parent3d76420512111006f678f820d1a20f866b07bdb9 (diff)
downloadpleroma-035368d363e31bd99efb21e1c121574718c81b5e.tar.gz
Rich Media: Skip Microformats hashtags
When fixing this problem I incorrectly assumed a.hashtag is the proper way for detecting hashtags, but it is just something Pleroma and Mastodon add. Per microformats it should be detected by the presense of rel=tag. This MR adds a check for rel=tag, but I still left a.hashtag just in case
-rw-r--r--lib/pleroma/html.ex2
-rw-r--r--test/html_test.exs16
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
index 8c226c944..2fae7281c 100644
--- a/lib/pleroma/html.ex
+++ b/lib/pleroma/html.ex
@@ -89,7 +89,7 @@ defmodule Pleroma.HTML do
Cachex.fetch!(:scrubber_cache, key, fn _key ->
result =
content
- |> Floki.filter_out("a.mention,a.hashtag")
+ |> Floki.filter_out("a.mention,a.hashtag,a[rel~=\"tag\"]")
|> Floki.attribute("a", "href")
|> Enum.at(0)
diff --git a/test/html_test.exs b/test/html_test.exs
index 64513980b..b8906c46a 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -212,5 +212,21 @@ defmodule Pleroma.HTMLTest do
assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
end
+
+ test "skips microformats hashtags" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "<a href=\"https://pleroma.gov/tags/cofe\" rel=\"tag\">#cofe</a> https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140",
+ "content_type" => "text/html"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+
+ assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ end
end
end