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.
This commit is contained in:
Lain Soykaf 2026-10-22 16:25:54 +04:00
commit de6ac2392c
No known key found for this signature in database
2 changed files with 12 additions and 1 deletions

View file

@ -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

View file

@ -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(<p><a href="https://example.org/"><strong>hello</strong></a></p>)
assert Formatter.markdown_to_html("[`code`](https://example.org/)", opts) ==
~s(<p><a href="https://example.org/"><code class="inline">code</code></a></p>)
end
test "escapes link attribute values" do
markdown = ~s|[click](http://example.com/?a=x" onerror="alert(1))|