From b3b6df6e3034051d87bb2dc9ddc3f74bcce5fab2 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 06:19:48 -0400 Subject: [PATCH 01/11] Remove emoji regex --- osu.Game/Online/Chat/MessageFormatter.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Online/Chat/MessageFormatter.cs b/osu.Game/Online/Chat/MessageFormatter.cs index f89939d7cf..792780595f 100644 --- a/osu.Game/Online/Chat/MessageFormatter.cs +++ b/osu.Game/Online/Chat/MessageFormatter.cs @@ -283,8 +283,6 @@ namespace osu.Game.Online.Chat while (space-- > 0) empty += "\0"; - handleMatches(emoji_regex, empty, "{0}", result, startIndex); - return result; } From b05ba8c501cd1d43b19bbe057ca939fdca6e4f06 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 06:32:33 -0400 Subject: [PATCH 02/11] Remove unused code --- osu.Game/Online/Chat/MessageFormatter.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Game/Online/Chat/MessageFormatter.cs b/osu.Game/Online/Chat/MessageFormatter.cs index 792780595f..6ca651bc87 100644 --- a/osu.Game/Online/Chat/MessageFormatter.cs +++ b/osu.Game/Online/Chat/MessageFormatter.cs @@ -279,10 +279,6 @@ namespace osu.Game.Online.Chat // handle channels handleMatches(channel_regex, "{0}", $@"{OsuGameBase.OSU_PROTOCOL}chan/{{0}}", result, startIndex, LinkAction.OpenChannel); - string empty = ""; - while (space-- > 0) - empty += "\0"; - return result; } From d62cfc16166ff48f07778a67d37fe939e71e80c0 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 20:24:09 -0400 Subject: [PATCH 03/11] Parse emoji to an empty string --- osu.Game/Online/Chat/MessageFormatter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Online/Chat/MessageFormatter.cs b/osu.Game/Online/Chat/MessageFormatter.cs index 6ca651bc87..3e03cc287b 100644 --- a/osu.Game/Online/Chat/MessageFormatter.cs +++ b/osu.Game/Online/Chat/MessageFormatter.cs @@ -256,6 +256,9 @@ namespace osu.Game.Online.Chat private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3) { + // see: https://github.com/ppy/osu/pull/24190 + toFormat = Regex.Replace(toFormat, emoji_regex.ToString(), string.Empty); + var result = new MessageFormatterResult(toFormat); // handle the [link display] format From 5a43de1ace9e81e8e838c077f4fc79d5dbb1d229 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 21:13:10 -0400 Subject: [PATCH 04/11] Update test cases --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index 3c35dc311f..fef8054c70 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -478,7 +478,7 @@ namespace osu.Game.Tests.Chat Content = "This is a [http://www.simple-test.com simple test] with some [traps] and [[wiki links]]. Don't forget to visit https://osu.ppy.sh (now!)[http://google.com]\uD83D\uDE12" }); - Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now!\0\0\0", result.DisplayContent); + Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now!", result.DisplayContent); Assert.AreEqual(5, result.Links.Count); Link f = result.Links.Find(l => l.Url == "https://dev.ppy.sh/wiki/wiki links"); @@ -508,6 +508,7 @@ namespace osu.Game.Tests.Chat } [Test] + [Ignore("https://github.com/ppy/osu/pull/24190")] public void TestEmoji() { Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" }); From 3d256acfef02706afcb51316161314dd46edd19d Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 21:40:49 -0400 Subject: [PATCH 05/11] Delete emoji test in TestLinkComplex --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index fef8054c70..5c063a5c6c 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -500,11 +500,6 @@ namespace osu.Game.Tests.Chat Assert.That(f, Is.Not.Null); Assert.AreEqual(78, f.Index); Assert.AreEqual(18, f.Length); - - f = result.Links.Find(l => l.Url == "\uD83D\uDE12"); - Assert.That(f, Is.Not.Null); - Assert.AreEqual(101, f.Index); - Assert.AreEqual(3, f.Length); } [Test] From f44e6e510d967792e55b86b7163a9d70addcf499 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Wed, 12 Jul 2023 22:42:12 -0400 Subject: [PATCH 06/11] 5 -> 4 --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index 5c063a5c6c..aa45e360e6 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -479,7 +479,7 @@ namespace osu.Game.Tests.Chat }); Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now!", result.DisplayContent); - Assert.AreEqual(5, result.Links.Count); + Assert.AreEqual(4, result.Links.Count); Link f = result.Links.Find(l => l.Url == "https://dev.ppy.sh/wiki/wiki links"); Assert.That(f, Is.Not.Null); From 3d17a03dc696c340ca690716a380f83a500e3013 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Thu, 13 Jul 2023 01:09:35 -0400 Subject: [PATCH 07/11] Emojis now represented as "[emoji]" --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 7 +++---- osu.Game/Online/Chat/MessageFormatter.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index aa45e360e6..529b28318a 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -478,7 +478,7 @@ namespace osu.Game.Tests.Chat Content = "This is a [http://www.simple-test.com simple test] with some [traps] and [[wiki links]]. Don't forget to visit https://osu.ppy.sh (now!)[http://google.com]\uD83D\uDE12" }); - Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now!", result.DisplayContent); + Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now![emoji]", result.DisplayContent); Assert.AreEqual(4, result.Links.Count); Link f = result.Links.Find(l => l.Url == "https://dev.ppy.sh/wiki/wiki links"); @@ -503,11 +503,10 @@ namespace osu.Game.Tests.Chat } [Test] - [Ignore("https://github.com/ppy/osu/pull/24190")] public void TestEmoji() { - Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" }); - Assert.AreEqual("Hello world\0\0\0<--This is an emoji,There are more:\0\0\0\0\0\0,\0\0\0", result.DisplayContent); + Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more emojis among us:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" }); + Assert.AreEqual("Hello world[emoji]<--This is an emoji,There are more emojis among us:[emoji][emoji],[emoji]", result.DisplayContent); Assert.AreEqual(result.Links.Count, 4); Assert.AreEqual(result.Links[0].Index, 11); Assert.AreEqual(result.Links[1].Index, 49); diff --git a/osu.Game/Online/Chat/MessageFormatter.cs b/osu.Game/Online/Chat/MessageFormatter.cs index 3e03cc287b..7a3941038e 100644 --- a/osu.Game/Online/Chat/MessageFormatter.cs +++ b/osu.Game/Online/Chat/MessageFormatter.cs @@ -257,7 +257,7 @@ namespace osu.Game.Online.Chat private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3) { // see: https://github.com/ppy/osu/pull/24190 - toFormat = Regex.Replace(toFormat, emoji_regex.ToString(), string.Empty); + toFormat = Regex.Replace(toFormat, emoji_regex.ToString(), "[emoji]"); var result = new MessageFormatterResult(toFormat); From 403a7aa0006d7103100b02344665918526462df9 Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Thu, 13 Jul 2023 04:28:35 -0400 Subject: [PATCH 08/11] 0 links are expected --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index 529b28318a..4d18a3d0bb 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -507,7 +507,7 @@ namespace osu.Game.Tests.Chat { Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more emojis among us:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" }); Assert.AreEqual("Hello world[emoji]<--This is an emoji,There are more emojis among us:[emoji][emoji],[emoji]", result.DisplayContent); - Assert.AreEqual(result.Links.Count, 4); + Assert.AreEqual(result.Links.Count, 0); Assert.AreEqual(result.Links[0].Index, 11); Assert.AreEqual(result.Links[1].Index, 49); Assert.AreEqual(result.Links[2].Index, 52); From ea6704ca1d528df6b94028aa2f82836e16947afe Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Thu, 13 Jul 2023 04:41:53 -0400 Subject: [PATCH 09/11] Move parsing --- osu.Game/Online/Chat/MessageFormatter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/Chat/MessageFormatter.cs b/osu.Game/Online/Chat/MessageFormatter.cs index 7a3941038e..10a005d71a 100644 --- a/osu.Game/Online/Chat/MessageFormatter.cs +++ b/osu.Game/Online/Chat/MessageFormatter.cs @@ -256,9 +256,6 @@ namespace osu.Game.Online.Chat private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3) { - // see: https://github.com/ppy/osu/pull/24190 - toFormat = Regex.Replace(toFormat, emoji_regex.ToString(), "[emoji]"); - var result = new MessageFormatterResult(toFormat); // handle the [link display] format @@ -282,6 +279,9 @@ namespace osu.Game.Online.Chat // handle channels handleMatches(channel_regex, "{0}", $@"{OsuGameBase.OSU_PROTOCOL}chan/{{0}}", result, startIndex, LinkAction.OpenChannel); + // see: https://github.com/ppy/osu/pull/24190 + result.Text = Regex.Replace(result.Text, emoji_regex.ToString(), "[emoji]"); + return result; } From 71351d898247d0329dca7726e0bc3965edb8dffd Mon Sep 17 00:00:00 2001 From: Andrew Hong Date: Thu, 13 Jul 2023 05:06:23 -0400 Subject: [PATCH 10/11] I forgor to remove these --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index 4d18a3d0bb..46dc47bf53 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -508,14 +508,6 @@ namespace osu.Game.Tests.Chat Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more emojis among us:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" }); Assert.AreEqual("Hello world[emoji]<--This is an emoji,There are more emojis among us:[emoji][emoji],[emoji]", result.DisplayContent); Assert.AreEqual(result.Links.Count, 0); - Assert.AreEqual(result.Links[0].Index, 11); - Assert.AreEqual(result.Links[1].Index, 49); - Assert.AreEqual(result.Links[2].Index, 52); - Assert.AreEqual(result.Links[3].Index, 56); - Assert.AreEqual(result.Links[0].Url, "\uD83D\uDE12"); - Assert.AreEqual(result.Links[1].Url, "\uD83D\uDE10"); - Assert.AreEqual(result.Links[2].Url, "\uD83D\uDE00"); - Assert.AreEqual(result.Links[3].Url, "\uD83D\uDE20"); } [Test] From 4859b8c9947a3b6d9acb39767da6a84939ed0c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 Jul 2023 20:49:34 +0200 Subject: [PATCH 11/11] Add some extra text coverage against potential emoji-to-link misparses --- osu.Game.Tests/Chat/MessageFormatterTests.cs | 8 ++++++++ osu.Game.Tests/Visual/Online/TestSceneChatLink.cs | 1 + 2 files changed, 9 insertions(+) diff --git a/osu.Game.Tests/Chat/MessageFormatterTests.cs b/osu.Game.Tests/Chat/MessageFormatterTests.cs index 46dc47bf53..47f4410b07 100644 --- a/osu.Game.Tests/Chat/MessageFormatterTests.cs +++ b/osu.Game.Tests/Chat/MessageFormatterTests.cs @@ -510,6 +510,14 @@ namespace osu.Game.Tests.Chat Assert.AreEqual(result.Links.Count, 0); } + [Test] + public void TestEmojiWithSuccessiveParens() + { + Message result = MessageFormatter.FormatMessage(new Message { Content = "\uD83D\uDE10(let's hope this doesn't accidentally turn into a link)" }); + Assert.AreEqual("[emoji](let's hope this doesn't accidentally turn into a link)", result.DisplayContent); + Assert.AreEqual(result.Links.Count, 0); + } + [Test] public void TestAbsoluteExternalLinks() { diff --git a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs index f5cf4c1ff2..ecf9b68297 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs @@ -89,6 +89,7 @@ namespace osu.Game.Tests.Visual.Online addMessageWithChecks($"Join my {OsuGameBase.OSU_PROTOCOL}chan/#english.", 1, expectedActions: LinkAction.OpenChannel); addMessageWithChecks("Join my #english or #japanese channels.", 2, expectedActions: new[] { LinkAction.OpenChannel, LinkAction.OpenChannel }); addMessageWithChecks("Join my #english or #nonexistent #hashtag channels.", 1, expectedActions: LinkAction.OpenChannel); + addMessageWithChecks("Hello world\uD83D\uDE12(<--This is an emoji). There are more:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20"); void addMessageWithChecks(string text, int linkAmount = 0, bool isAction = false, bool isImportant = false, params LinkAction[] expectedActions) {