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:
parent
1f2179872a
commit
de6ac2392c
2 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))|
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue