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