From cd36c629358f050ca5e85d982f41536fba418f3b Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 11 Feb 2021 00:45:55 -0500 Subject: [PATCH 1/2] escape URL regex --- .../Tools/StatusExtractor.cs | 2 +- .../Tools/StatusExtractorTests.cs | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs index 7df4c0e..5cbff68 100644 --- a/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs +++ b/src/BirdsiteLive.Domain/Tools/StatusExtractor.cs @@ -64,7 +64,7 @@ namespace BirdsiteLive.Domain.Tools secondPart = truncatedUrl.Substring(30); } - messageContent = Regex.Replace(messageContent, m.ToString(), + messageContent = Regex.Replace(messageContent, Regex.Escape(m.ToString()), $@"{m.Groups[1]}{protocol}{firstPart}{secondPart}"); } diff --git a/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs b/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs index 06d8f9a..a279dd0 100644 --- a/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs +++ b/src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs @@ -217,6 +217,25 @@ namespace BirdsiteLive.Domain.Tests.Tools #endregion } + [TestMethod] + public void Extract_UrlRegexChars_Test() + { + #region Stubs + var message = @"🐣 juniors & tech(http://tech.guru maker)"; + #endregion + + #region Mocks + var logger = new Mock>(); + #endregion + + var service = new StatusExtractor(_settings, logger.Object); + var result = service.Extract(message); + + #region Validations + Assert.AreEqual(@"🐣 juniors & tech(http://tech.guru maker)", result.content); + #endregion + } + [TestMethod] public void Extract_SingleHashTag_Test() { @@ -345,7 +364,7 @@ namespace BirdsiteLive.Domain.Tests.Tools Assert.IsTrue(result.content.Contains(@"@mynickname")); #endregion } - + [TestMethod] public void Extract_SingleMentionTag_RT_Test() { From 9bdca4e202c303d9f8835d385ed87a225fac5b58 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Thu, 11 Feb 2021 20:11:32 -0500 Subject: [PATCH 2/2] road to 0.14.3 --- 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 7c24384..26df777 100644 --- a/src/BirdsiteLive/BirdsiteLive.csproj +++ b/src/BirdsiteLive/BirdsiteLive.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 d21486de-a812-47eb-a419-05682bb68856 Linux - 0.14.2 + 0.14.3