Turn on markup normalisation by default
[akkoma] / lib / pleroma / web / activity_pub / mrf.ex
index 4df226e80eb09de8754e8bb55e69c6a1f3b6362f..064ffc527adef1b085a334255ad3897b32b8f2e5 100644 (file)
@@ -140,7 +140,8 @@ defmodule Pleroma.Web.ActivityPub.MRF do
     |> get_policies()
     |> Enum.concat([
       Pleroma.Web.ActivityPub.MRF.HashtagPolicy,
-      Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy
+      Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy,
+      Pleroma.Web.ActivityPub.MRF.NormalizeMarkup
     ])
     |> Enum.uniq()
   end
@@ -149,9 +150,20 @@ defmodule Pleroma.Web.ActivityPub.MRF do
   defp get_policies(policies) when is_list(policies), do: policies
   defp get_policies(_), do: []
 
+  # Matches the following:
+  # - https://baddomain.net
+  # - https://extra.baddomain.net/
+  # Does NOT match the following:
+  # - https://maybebaddomain.net/
+  def subdomain_regex("*." <> domain), do: subdomain_regex(domain)
+
+  def subdomain_regex(domain) do
+    ~r/^(.+\.)?#{Regex.escape(domain)}$/i
+  end
+
   @spec subdomains_regex([String.t()]) :: [Regex.t()]
   def subdomains_regex(domains) when is_list(domains) do
-    for domain <- domains, do: ~r(^#{String.replace(domain, "*.", "(.*\\.)*")}$)i
+    Enum.map(domains, &subdomain_regex/1)
   end
 
   @spec subdomain_match?([Regex.t()], String.t()) :: boolean()