Merge branch 'tusooa/2810-punycode-mention' into 'develop'

Fix mentioning punycode domains when using Markdown

Closes #2810

See merge request pleroma/pleroma!3925
This commit is contained in:
Haelwenn 2023-10-18 01:20:00 +00:00
commit e3ea311cd5
4 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1 @@
Fix mentioning punycode domains when using Markdown

View File

@ -124,7 +124,7 @@ def mentions_escape(text, options \\ []) do
end end
def markdown_to_html(text) do def markdown_to_html(text) do
Earmark.as_html!(text, %Earmark.Options{compact_output: true}) Earmark.as_html!(text, %Earmark.Options{compact_output: true, smartypants: false})
end end
def html_escape({text, mentions, hashtags}, type) do def html_escape({text, mentions, hashtags}, type) do

View File

@ -200,7 +200,7 @@ test "local mentions" do
{result, _, []} = Utils.format_input(code, "text/markdown") {result, _, []} = Utils.format_input(code, "text/markdown")
assert result == assert result ==
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo whats up?</p>] ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what&#39;s up?</p>]
end end
test "remote mentions" do test "remote mentions" do
@ -211,7 +211,7 @@ test "remote mentions" do
{result, _, []} = Utils.format_input(code, "text/markdown") {result, _, []} = Utils.format_input(code, "text/markdown")
assert result == assert result ==
~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo whats up?</p>] ~s[<p><span class="h-card"><a class="u-url mention" data-user="#{mario.id}" href="#{mario.ap_id}" rel="ugc">@<span>mario</span></a></span> <span class="h-card"><a class="u-url mention" data-user="#{luigi.id}" href="#{luigi.ap_id}" rel="ugc">@<span>luigi</span></a></span> yo what&#39;s up?</p>]
end end
test "raw HTML" do test "raw HTML" do
@ -229,7 +229,7 @@ test "rulers" do
test "blockquote" do test "blockquote" do
code = ~s[> whoms't are you quoting?] code = ~s[> whoms't are you quoting?]
{result, [], []} = Utils.format_input(code, "text/markdown") {result, [], []} = Utils.format_input(code, "text/markdown")
assert result == "<blockquote><p>whomst are you quoting?</p></blockquote>" assert result == "<blockquote><p>whoms&#39;t are you quoting?</p></blockquote>"
end end
test "code" do test "code" do

View File

@ -843,6 +843,18 @@ test "quote posting visibility" do
{:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id}) {:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id})
{:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: public.id}) {:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: public.id})
end end
test "it properly mentions punycode domain" do
user = insert(:user)
_mentioned_user =
insert(:user, ap_id: "https://xn--i2raa.com/users/yyy", nickname: "yyy@xn--i2raa.com")
{:ok, activity} =
CommonAPI.post(user, %{status: "hey @yyy@xn--i2raa.com", content_type: "text/markdown"})
assert "https://xn--i2raa.com/users/yyy" in Object.normalize(activity).data["to"]
end
end end
describe "reactions" do describe "reactions" do