summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-06-14 11:52:04 +0000
committerlain <lain@soykaf.club>2019-06-14 11:52:04 +0000
commit7f48b90bfb8410606e4d733af8b212bea8534db2 (patch)
tree138c47b17307cdd722de3e4fda95cd16c4c4dab5
parenta971b357855dd2eac019a8ee91c1c79864cbcf77 (diff)
parentd0ebc0edf31945181a941dca891fce7b3d5637ab (diff)
downloadpleroma-7f48b90bfb8410606e4d733af8b212bea8534db2.tar.gz
pleroma-7f48b90bfb8410606e4d733af8b212bea8534db2.zip
Merge branch 'fix/hashtag-rich-media' into 'develop'
Fix hashtags being picked up by rich media parser Closes #989 See merge request pleroma/pleroma!1288
-rw-r--r--lib/pleroma/html.ex2
-rw-r--r--test/html_test.exs53
2 files changed, 54 insertions, 1 deletions
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
index e5e78ee4f..8c226c944 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")
+ |> Floki.filter_out("a.mention,a.hashtag")
|> Floki.attribute("a", "href")
|> Enum.at(0)
diff --git a/test/html_test.exs b/test/html_test.exs
index 08738276e..64513980b 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -4,8 +4,12 @@
defmodule Pleroma.HTMLTest do
alias Pleroma.HTML
+ alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
+ import Pleroma.Factory
+
@html_sample """
<b>this is in bold</b>
<p>this is a paragraph</p>
@@ -160,4 +164,53 @@ defmodule Pleroma.HTMLTest do
)
end
end
+
+ describe "extract_first_external_url" do
+ test "extracts the url" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "I think I just found the best github repo https://github.com/komeiji-satori/Dress"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+ assert url == "https://github.com/komeiji-satori/Dress"
+ end
+
+ test "skips mentions" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
+ })
+
+ object = Object.normalize(activity)
+ {:ok, url} = HTML.extract_first_external_url(object, object.data["content"])
+
+ assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md"
+
+ refute url == other_user.ap_id
+ end
+
+ test "skips hashtags" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140"
+ })
+
+ 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