From b748efe66a099b66300f2beda42f5639911bab4a Mon Sep 17 00:00:00 2001 From: tusooa Date: Sat, 29 Jul 2023 12:55:43 -0400 Subject: [PATCH 1/2] Fix mentioning punycode domains when using Markdown --- changelog.d/punycode-mention.fix | 1 + lib/pleroma/formatter.ex | 2 +- test/pleroma/web/common_api_test.exs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 changelog.d/punycode-mention.fix diff --git a/changelog.d/punycode-mention.fix b/changelog.d/punycode-mention.fix new file mode 100644 index 000000000..f013c2dac --- /dev/null +++ b/changelog.d/punycode-mention.fix @@ -0,0 +1 @@ +Fix mentioning punycode domains when using Markdown diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index a46c3e381..11d5af2fb 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -124,7 +124,7 @@ defmodule Pleroma.Formatter do end 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 def html_escape({text, mentions, hashtags}, type) do diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index a98b16d4b..b21dd4e23 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -843,6 +843,18 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, _} = CommonAPI.post(user, %{status: "nice", quote_id: public.id}) {:ok, _} = CommonAPI.post(another_user, %{status: "nice", quote_id: public.id}) 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 describe "reactions" do From df0b56576a6863db9f1ca2c7987f2a465bd1f1c3 Mon Sep 17 00:00:00 2001 From: tusooa Date: Sun, 24 Sep 2023 22:46:30 -0400 Subject: [PATCH 2/2] Fix other quotation mark conversion tests --- test/pleroma/web/common_api/utils_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/pleroma/web/common_api/utils_test.exs b/test/pleroma/web/common_api/utils_test.exs index 4ce039d64..27b1da1e3 100644 --- a/test/pleroma/web/common_api/utils_test.exs +++ b/test/pleroma/web/common_api/utils_test.exs @@ -200,7 +200,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do {result, _, []} = Utils.format_input(code, "text/markdown") assert result == - ~s[

@mario @luigi yo what’s up?

] + ~s[

@mario @luigi yo what's up?

] end test "remote mentions" do @@ -211,7 +211,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do {result, _, []} = Utils.format_input(code, "text/markdown") assert result == - ~s[

@mario @luigi yo what’s up?

] + ~s[

@mario @luigi yo what's up?

] end test "raw HTML" do @@ -229,7 +229,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do test "blockquote" do code = ~s[> whoms't are you quoting?] {result, [], []} = Utils.format_input(code, "text/markdown") - assert result == "

whoms’t are you quoting?

" + assert result == "

whoms't are you quoting?

" end test "code" do