From 3a249f2c145d7dd3c6d345caee62931de579cef4 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 13 Jan 2021 02:03:51 -0500 Subject: [PATCH 1/3] fix parenthesis messing up with regex --- .../Tools/StatusExtractor.cs | 5 +++-- .../Tools/StatusExtractorTests.cs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs index 2e8d7a3..bdef5ee 100644 --- a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs +++ b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs @@ -44,6 +44,7 @@ public StatusExtractor(InstanceSettings instanceSettings) // Replace return lines messageContent = Regex.Replace(messageContent, @"\r\n\r\n?|\n\n", "

"); messageContent = Regex.Replace(messageContent, @"\r\n?|\n", "
"); + messageContent = Regex.Replace(messageContent, @"\(", "( "); // Secure emojis var emojiMatch = _emojiRegex.Matches(messageContent); @@ -83,7 +84,7 @@ public StatusExtractor(InstanceSettings instanceSettings) // Extract Hashtags var hashtagMatch = OrderByLength(_hastagRegex.Matches(messageContent)); - foreach (Match m in hashtagMatch) + foreach (Match m in hashtagMatch.OrderByDescending(x => x.Length)) { var tag = m.ToString().Replace("#", string.Empty).Replace("\n", string.Empty).Trim(); var url = $"https://{_instanceSettings.Domain}/tags/{tag}"; @@ -101,7 +102,7 @@ public StatusExtractor(InstanceSettings instanceSettings) // Extract Mentions var mentionMatch = OrderByLength(_mentionRegex.Matches(messageContent)); - foreach (Match m in mentionMatch) + foreach (Match m in mentionMatch.OrderByDescending(x => x.Length)) { var mention = m.ToString().Replace("@", string.Empty).Replace("\n", string.Empty).Trim(); var url = $"https://{_instanceSettings.Domain}/users/{mention}"; diff --git a/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs b/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs index 3edf9c8..32d1faa 100644 --- a/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs +++ b/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs @@ -335,5 +335,22 @@ public void Extract_Emoji_Test() Assert.IsTrue(result.content.Contains(@"😎 😍 🤗 🤩 😘")); #endregion } + + [TestMethod] + public void Extract_Parenthesis_Test() + { + #region Stubs + var message = $"bla (@mynickname test)"; + //var message = $"tests@mynickname"; + #endregion + + var service = new StatusExtractor(_settings); + var result = service.ExtractTags(message); + + #region Validations + Assert.AreEqual(1, result.tags.Length); + Assert.IsTrue(result.content.Equals(@"bla ( @mynickname test)")); + #endregion + } } } \ No newline at end of file From ddd29e9d3f239d9b2e91bc216c58e87b8305ad87 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 13 Jan 2021 02:06:38 -0500 Subject: [PATCH 2/3] road to 0.6.1 --- src/BirdsiteLive/BirdsiteLive.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BirdsiteLive/BirdsiteLive.csproj b/src/BirdsiteLive/BirdsiteLive.csproj index f38be3b..ea56b70 100644 --- a/src/BirdsiteLive/BirdsiteLive.csproj +++ b/src/BirdsiteLive/BirdsiteLive.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 d21486de-a812-47eb-a419-05682bb68856 Linux - 0.6.0 + 0.6.1 From 7e86cdc6c7dc09c2b99011075a51f9980204baa7 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Wed, 13 Jan 2021 02:08:54 -0500 Subject: [PATCH 3/3] limit fix to problematic chars --- src/BirdsiteLive.Domain/Tools/StatusExtractor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs index bdef5ee..ed401a6 100644 --- a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs +++ b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs @@ -44,7 +44,8 @@ public StatusExtractor(InstanceSettings instanceSettings) // Replace return lines messageContent = Regex.Replace(messageContent, @"\r\n\r\n?|\n\n", "

"); messageContent = Regex.Replace(messageContent, @"\r\n?|\n", "
"); - messageContent = Regex.Replace(messageContent, @"\(", "( "); + messageContent = Regex.Replace(messageContent, @"\(@", "( @"); + messageContent = Regex.Replace(messageContent, @"\(#", "( #"); // Secure emojis var emojiMatch = _emojiRegex.Matches(messageContent);