From 14d11877022b8ee4f770e0c851c0c6f324b31810 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 24 Aug 2018 18:14:19 +0000 Subject: [PATCH 1/3] test: add testcase for formatter issue #163 --- test/formatter_test.exs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/formatter_test.exs b/test/formatter_test.exs index abbd7ac93..b97b0e8b9 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -123,6 +123,35 @@ defmodule Pleroma.FormatterTest do assert expected_text == Formatter.finalize({subs, text}) end + + test "gives a replacement for single-character local nicknames" do + text = "@o hi" + o = insert(:user, %{nickname: "o"}) + + mentions = Formatter.parse_mentions(text) + + {subs, text} = Formatter.add_user_links({[], text}, mentions) + + assert length(subs) == 1 + Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) + + expected_text = "@o hi" + assert expected_text == Formatter.finalize({subs, text}) + end + + test "does not give a replacement for single-character local nicknames who don't exist" do + text = "@a hi" + + mentions = Formatter.parse_mentions(text) + + {subs, text} = Formatter.add_user_links({[], text}, mentions) + + assert length(subs) == 0 + Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) + + expected_text = "@a hi" + assert expected_text == Formatter.finalize({subs, text}) + end end describe ".parse_tags" do From 3e10d13909d3801d26b5cbf86a376e2ed370e2cc Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 24 Aug 2018 18:18:48 +0000 Subject: [PATCH 2/3] formatter: adjust regexp captures to match local users with single character nicknames (closes #163) --- lib/pleroma/formatter.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 3e71a3b5f..cf2944c38 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Formatter do def parse_mentions(text) do # Modified from https://www.w3.org/TR/html5/forms.html#valid-e-mail-address regex = - ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u + ~r/@[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]*@?[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/u Regex.scan(regex, text) |> List.flatten() From a8bd120ea620d3bb86018318bbc013de2c613af0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 24 Aug 2018 18:33:36 +0000 Subject: [PATCH 3/3] tests: formatting --- test/formatter_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/formatter_test.exs b/test/formatter_test.exs index b97b0e8b9..95558089b 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -135,7 +135,7 @@ defmodule Pleroma.FormatterTest do assert length(subs) == 1 Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) - expected_text = "@o hi" + expected_text = "@o hi" assert expected_text == Formatter.finalize({subs, text}) end