From de6ac2392cfcee2a2c283cf823333d25fe6983d4 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 22 Oct 2026 16:25:54 +0400 Subject: [PATCH] fix(formatter): keep links with formatted text in MFM posts The email autolink clause also matched a link whose only child is an element, raised on "mailto:" <> element, and the rescue turned the whole post into escaped source text. --- lib/pleroma/formatter.ex | 3 ++- test/pleroma/formatter_test.exs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 1cb9884a5..32ee6a296 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -169,7 +169,8 @@ defmodule Pleroma.Formatter do Enum.map(nodes, &strip_email_autolinks(&1, emails)) end - defp strip_email_autolinks({"a", attrs, [email], _meta} = node, emails) do + defp strip_email_autolinks({"a", attrs, [email], _meta} = node, emails) + when is_binary(email) do if List.keyfind(attrs, "href", 0) == {"href", "mailto:" <> email} and MapSet.member?(emails, email) do email diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs index 724b3075f..906d39e4f 100644 --- a/test/pleroma/formatter_test.exs +++ b/test/pleroma/formatter_test.exs @@ -375,6 +375,16 @@ defmodule Pleroma.FormatterTest do end describe "markdown_to_html/2" do + test "keeps formatted link text when stripping email autolinks" do + opts = %{breaks: true, strip_email_autolinks: true} + + assert Formatter.markdown_to_html("[**hello**](https://example.org/)", opts) == + ~s(

hello

) + + assert Formatter.markdown_to_html("[`code`](https://example.org/)", opts) == + ~s(

code

) + end + test "escapes link attribute values" do markdown = ~s|[click](http://example.com/?a=x" onerror="alert(1))|