Web.RelMe: Fix having other values in rel attr
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 5 Mar 2019 01:03:44 +0000 (02:03 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 5 Mar 2019 01:13:22 +0000 (02:13 +0100)
One example of this is Github which puts a rel="nofollow me" on the
profile link.

lib/pleroma/web/rel_me.ex
test/fixtures/rel_me_anchor_nofollow.html [new file with mode: 0644]
test/fixtures/rel_me_null.html
test/web/rel_me_test.exs

index a07db966f0b53970b0c681e421bf2d6502c94534..ab29a36e393deb27c4c1dee8c412ef11f6172a40 100644 (file)
@@ -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 (file)
index 0000000..c856f00
--- /dev/null
@@ -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>
index 57d424b8099282da4d9aaf6b8ce5faba96c0f48f..5ab5f10c10b97a70a5f4d73723eb56d07e1cb074 100644 (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">lain’s account</a>
        </article>
        </body>
 </html>
index ba8038e692b53dcccc6d75a25a66bab5e34404b5..5188f4de18cb68d92e0f78f17a80edf1a225b3e8 100644 (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 @@ 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