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.
This commit is contained in:
Haelwenn (lanodan) Monnier 2019-03-05 02:03:44 +01:00
parent 682cc94db1
commit 788a354ce0
No known key found for this signature in database
GPG Key ID: D5B7A8E43C997DEE
4 changed files with 29 additions and 1 deletions

View File

@ -28,7 +28,8 @@ defp parse_url(url) 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

View File

@ -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">lains account</a>
</article>
</body>
</html>

View File

@ -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">lains account</a>
</article>
</body>
</html>

View File

@ -9,6 +9,12 @@ defmodule Pleroma.Web.RelMeTest do
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
%{
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"
@ -33,6 +39,7 @@ test "parse/1" 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 @@ test "maybe_put_rel_me/2" 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