Merge branch 'bugfix/webfinger-xml-crash' into 'develop'
[akkoma] / lib / pleroma / web / web_finger / web_finger.ex
index b955bc43f9ca7c625661fdcba7bd62f4e76f1444..0b417479d069a59b3c0950b75d3870f2ffc075b7 100644 (file)
@@ -86,7 +86,11 @@ defmodule Pleroma.Web.WebFinger do
           "href" => "data:application/magic-public-key,#{magic_key}"
         },
         %{"rel" => "self", "type" => "application/activity+json", "href" => user.ap_id},
-        %{"rel" => "self", "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "href" => user.ap_id},
+        %{
+          "rel" => "self",
+          "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
+          "href" => user.ap_id
+        },
         %{
           "rel" => "http://ostatus.org/schema/1.0/subscribe",
           "template" => OStatus.remote_follow_path()
@@ -118,7 +122,6 @@ defmodule Pleroma.Web.WebFinger do
         {:Link,
          %{rel: "magic-public-key", href: "data:application/magic-public-key,#{magic_key}"}},
         {:Link, %{rel: "self", type: "application/activity+json", href: user.ap_id}},
-        {:Link, %{rel: "self", type: "application/ld+json; profile="https://www.w3.org/ns/activitystreams"", href: user.ap_id}},
         {:Link,
          %{rel: "http://ostatus.org/schema/1.0/subscribe", template: OStatus.remote_follow_path()}}
       ]
@@ -166,14 +169,6 @@ defmodule Pleroma.Web.WebFinger do
         doc
       )
 
-    if ap_id == nil do
-      ap_id =
-        XML.string_from_xpath(
-          ~s{//Link[@rel="self" and @type="application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""]/@href},
-          doc
-        )
-    end
-
     data = %{
       "magic_key" => magic_key,
       "topic" => topic,
@@ -219,7 +214,7 @@ defmodule Pleroma.Web.WebFinger do
   end
 
   def get_template_from_xml(body) do
-    xpath = "//Link[@rel='lrdd' and @type='application/xrd+xml']/@template"
+    xpath = "//Link[@rel='lrdd']/@template"
 
     with doc when doc != :error <- XML.parse_document(body),
          template when template != nil <- XML.string_from_xpath(xpath, doc) do
@@ -258,7 +253,7 @@ defmodule Pleroma.Web.WebFinger do
           String.replace(template, "{uri}", URI.encode(account))
 
         _ ->
-          "http://#{domain}/.well-known/webfinger?resource=acct:#{account}"
+          "https://#{domain}/.well-known/webfinger?resource=acct:#{account}"
       end
 
     with response <-