activitypub: normalize the actor to ensure we have its URI
[akkoma] / lib / pleroma / formatter.ex
index 9396b182682cd2dd99b4b35b8341e68df20b8970..456416fbdff4eecc6127ee9ea36bbd486cc6ecd7 100644 (file)
@@ -144,7 +144,7 @@ defmodule Pleroma.Formatter do
     @emoji
   end
 
-  @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&@~\(\)]+[\w\/]/u
+  @link_regex ~r/https?:\/\/[\w\.\/?=\-#\+%&@~'\(\):]+[\w\/]/u
 
   def html_escape(text) do
     Regex.split(@link_regex, text, include_captures: true)
@@ -168,7 +168,13 @@ defmodule Pleroma.Formatter do
     subs =
       subs ++
         Enum.map(links, fn {uuid, url} ->
-          {uuid, "<a href='#{url}'>#{url}</a>"}
+          {:safe, link} = Phoenix.HTML.Link.link(url, to: url)
+
+          link =
+            link
+            |> IO.iodata_to_binary()
+
+          {uuid, link}
         end)
 
     {subs, uuid_text}
@@ -189,7 +195,9 @@ defmodule Pleroma.Formatter do
 
     subs =
       subs ++
-        Enum.map(mentions, fn {match, %User{ap_id: ap_id}, uuid} ->
+        Enum.map(mentions, fn {match, %User{ap_id: ap_id, info: info}, uuid} ->
+          ap_id = info["source_data"]["url"] || ap_id
+
           short_match = String.split(match, "@") |> tl() |> hd()
           {uuid, "<span><a href='#{ap_id}'>@<span>#{short_match}</span></a></span>"}
         end)