aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-03-05 02:03:44 +0100
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-03-05 02:13:22 +0100
commit788a354ce0cbe91d0430ce48db62cb537e845a6d (patch)
treee8c802ddf1d95420dafb13911aa20a91c2b1b47f
parent682cc94db11404ad658f566634c1e641cc575091 (diff)
downloadpleroma-788a354ce0cbe91d0430ce48db62cb537e845a6d.tar.gz
Web.RelMe: Fix having other values in rel attr
One example of this is Github which puts a rel="nofollow me" on the profile link.
-rw-r--r--lib/pleroma/web/rel_me.ex3
-rw-r--r--test/fixtures/rel_me_anchor_nofollow.html14
-rw-r--r--test/fixtures/rel_me_null.html1
-rw-r--r--test/web/rel_me_test.exs12
4 files changed, 29 insertions, 1 deletions
diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex
index a07db966f..ab29a36e3 100644
--- a/lib/pleroma/web/rel_me.ex
+++ b/lib/pleroma/web/rel_me.ex
@@ -28,7 +28,8 @@ defmodule Pleroma.Web.RelMe do
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
data =
- Floki.attribute(html, "link[rel=me]", "href") ++ Floki.attribute(html, "a[rel=me]", "href")
+ Floki.attribute(html, "link[rel~=me]", "href") ++
+ Floki.attribute(html, "a[rel~=me]", "href")
{:ok, data}
rescue
diff --git a/test/fixtures/rel_me_anchor_nofollow.html b/test/fixtures/rel_me_anchor_nofollow.html
new file mode 100644
index 000000000..c856f0091
--- /dev/null
+++ b/test/fixtures/rel_me_anchor_nofollow.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <title>Blog</title>
+ </head>
+ <body>
+ <article>
+ <h1>Lorem ipsum</h1>
+ <p>Lorem ipsum dolor sit ameph, …</p>
+ <a rel="me nofollow" href="https://social.example.org/users/lain">lain’s account</a>
+ </article>
+ </body>
+</html>
diff --git a/test/fixtures/rel_me_null.html b/test/fixtures/rel_me_null.html
index 57d424b80..5ab5f10c1 100644
--- a/test/fixtures/rel_me_null.html
+++ b/test/fixtures/rel_me_null.html
@@ -8,6 +8,7 @@
<article>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit ameph, …</p>
+ <a rel="nofollow" href="https://social.example.org/users/lain">lain’s account</a>
</article>
</body>
</html>
diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs
index ba8038e69..5188f4de1 100644
--- a/test/web/rel_me_test.exs
+++ b/test/web/rel_me_test.exs
@@ -11,6 +11,12 @@ defmodule Pleroma.Web.RelMeTest do
%{
method: :get,
+ url: "http://example.com/rel_me/anchor_nofollow"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
+
+ %{
+ method: :get,
url: "http://example.com/rel_me/link"
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
@@ -33,6 +39,7 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
+ assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
end
test "maybe_put_rel_me/2" do
@@ -49,6 +56,11 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
attr
+ assert Pleroma.Web.RelMe.maybe_put_rel_me(
+ "http://example.com/rel_me/anchor_nofollow",
+ profile_urls
+ ) == attr
+
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
attr
end