From 590a10af332650a8a1eb61db7db7457dc63f229a Mon Sep 17 00:00:00 2001 From: Mary Kate Date: Thu, 24 Dec 2020 16:40:08 -0600 Subject: [PATCH 1/5] Adds tests for breaking tag and mention links after text is converted from markdown to html --- test/pleroma/formatter_test.exs | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs index 5781a3f01..f47331bc3 100644 --- a/test/pleroma/formatter_test.exs +++ b/test/pleroma/formatter_test.exs @@ -284,6 +284,34 @@ test "it correctly parses angry face D:< with mention" do assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text) end + + test "correctly parses mentions in html" do + text = "

@lain hello

" + lain = insert(:user, %{nickname: "lain"}) + + {text, mentions, []} = Formatter.linkify(text) + + assert length(mentions) == 1 + + expected_text = + ~s(

@lain hello

) + + assert expected_text == text + end + + test "correctly parses mentions on the last line of html" do + text = "

Hello

@lain

" + lain = insert(:user, %{nickname: "lain"}) + + {text, mentions, []} = Formatter.linkify(text) + + assert length(mentions) == 1 + + expected_text = + ~s(

Hello

@lain

) + + assert expected_text == text + end end describe ".parse_tags" do @@ -299,6 +327,56 @@ test "parses tags in the text" do assert {_text, [], ^expected_tags} = Formatter.linkify(text) end + + test "parses tags in html" do + text = "

This is a #test

" + + expected_tags = [ + {"#test", "test"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses mulitple tags in html" do + text = "

#tag1 #tag2 #tag3 #tag4

" + + expected_tags = [ + {"#tag1", "tag1"}, + {"#tag2", "tag2"}, + {"#tag3", "tag3"}, + {"#tag4", "tag4"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses tags on the last line of html" do + text = "

This is a

#test

" + + expected_tags = [ + {"#test", "test"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses mulitple tags on mulitple lines in html" do + text = "

testing...

#tag1 #tag2 #tag3 #tag4

paragraph

#tag5 #tag6 #tag7 #tag8

" + + expected_tags = [ + {"#tag1", "tag1"}, + {"#tag2", "tag2"}, + {"#tag3", "tag3"}, + {"#tag4", "tag4"}, + {"#tag5", "tag5"}, + {"#tag6", "tag6"}, + {"#tag7", "tag7"}, + {"#tag8", "tag8"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end end test "it escapes HTML in plain text" do From d5eb44e8b39a3a896cf3457a2ca6f2055eebc982 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 15 Jan 2022 12:27:16 -0600 Subject: [PATCH 2/5] Upgrade Linkify to v0.5.2 --- mix.exs | 2 +- mix.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 62010d166..4387cb0aa 100644 --- a/mix.exs +++ b/mix.exs @@ -157,7 +157,7 @@ defp deps do {:floki, "~> 0.27"}, {:timex, "~> 3.6"}, {:ueberauth, "~> 0.4"}, - {:linkify, "~> 0.5.1"}, + {:linkify, "~> 0.5.2"}, {:http_signatures, "~> 0.1.1"}, {:telemetry, "~> 0.3"}, {:poolboy, "~> 1.5"}, diff --git a/mix.lock b/mix.lock index 05630a92e..817240538 100644 --- a/mix.lock +++ b/mix.lock @@ -69,7 +69,7 @@ "jose": {:hex, :jose, "1.11.1", "59da64010c69aad6cde2f5b9248b896b84472e99bd18f246085b7b9fe435dcdb", [:mix, :rebar3], [], "hexpm", "078f6c9fb3cd2f4cfafc972c814261a7d1e8d2b3685c0a76eb87e158efff1ac5"}, "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"}, "libring": {:hex, :libring, "1.4.0", "41246ba2f3fbc76b3971f6bce83119dfec1eee17e977a48d8a9cfaaf58c2a8d6", [:mix], [], "hexpm"}, - "linkify": {:hex, :linkify, "0.5.1", "6dc415cbc948b2f6ecec7cb226aab7ba9d3a1815bb501ae33e042334d707ecee", [:mix], [], "hexpm", "a3128c7e22fada4aa7214009501d8131e1fa3faf2f0a68b33dba379dc84ff944"}, + "linkify": {:hex, :linkify, "0.5.2", "fb66be139fdf1656ecb31f78a93592724d1b78d960a1b3598bd661013ea0e3c7", [:mix], [], "hexpm", "8d71ac690218d8952c90cbeb63cb8cc33738bb230d8a56d487d9447f2a5eab86"}, "majic": {:hex, :majic, "1.0.0", "37e50648db5f5c2ff0c9fb46454d034d11596c03683807b9fb3850676ffdaab3", [:make, :mix], [{:elixir_make, "~> 0.6.1", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "7905858f76650d49695f14ea55cd9aaaee0c6654fa391671d4cf305c275a0a9e"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, From 31148c1857dae28377f9b864a9ebe143d99beb96 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 15 Jan 2022 12:31:36 -0600 Subject: [PATCH 3/5] FormatterTest: fix nesting in expected output --- test/pleroma/formatter_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs index 5b8babc83..045edf4b1 100644 --- a/test/pleroma/formatter_test.exs +++ b/test/pleroma/formatter_test.exs @@ -294,7 +294,7 @@ test "correctly parses mentions on the last line of html" do assert length(mentions) == 1 expected_text = - ~s(

Hello

@lain

) + ~s(

Hello

@lain

) assert expected_text == text end From cd8f1aac477935176ad5413bbe237b3791c7d9a4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 15 Jan 2022 12:36:33 -0600 Subject: [PATCH 4/5] CHANGELOG: hashtags markdown fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d214fde8b..ca519a668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Handle Reject for already-accepted Follows properly - Display OpenGraph data on alternative notice routes. - Fix replies count for remote replies +- Fixed hashtags disappearing from the end of lines when Markdown is enabled - ChatAPI: Add link headers - Limited number of search results to 40 to prevent DoS attacks - ActivityPub: fixed federation of attachment dimensions From 39c5ebb1f634b691d06d607d91cbfc6b0741d541 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 15 Jan 2022 12:55:12 -0600 Subject: [PATCH 5/5] mix format --- test/pleroma/formatter_test.exs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs index 045edf4b1..6663fdbc6 100644 --- a/test/pleroma/formatter_test.exs +++ b/test/pleroma/formatter_test.exs @@ -318,7 +318,7 @@ test "parses tags in html" do text = "

This is a #test

" expected_tags = [ - {"#test", "test"}, + {"#test", "test"} ] assert {_text, [], ^expected_tags} = Formatter.linkify(text) @@ -331,7 +331,7 @@ test "parses mulitple tags in html" do {"#tag1", "tag1"}, {"#tag2", "tag2"}, {"#tag3", "tag3"}, - {"#tag4", "tag4"}, + {"#tag4", "tag4"} ] assert {_text, [], ^expected_tags} = Formatter.linkify(text) @@ -341,14 +341,15 @@ test "parses tags on the last line of html" do text = "

This is a

#test

" expected_tags = [ - {"#test", "test"}, + {"#test", "test"} ] assert {_text, [], ^expected_tags} = Formatter.linkify(text) end test "parses mulitple tags on mulitple lines in html" do - text = "

testing...

#tag1 #tag2 #tag3 #tag4

paragraph

#tag5 #tag6 #tag7 #tag8

" + text = + "

testing...

#tag1 #tag2 #tag3 #tag4

paragraph

#tag5 #tag6 #tag7 #tag8

" expected_tags = [ {"#tag1", "tag1"}, @@ -358,7 +359,7 @@ test "parses mulitple tags on mulitple lines in html" do {"#tag5", "tag5"}, {"#tag6", "tag6"}, {"#tag7", "tag7"}, - {"#tag8", "tag8"}, + {"#tag8", "tag8"} ] assert {_text, [], ^expected_tags} = Formatter.linkify(text)