From 0ee22813fa48870cffeea9c2c61a8fea5d2c3ca0 Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 24 Jun 2020 17:19:01 +0200 Subject: [PATCH] Don't trim inner string when matching proxy tags --- PluralKit.Bot/Proxy/ProxyTagParser.cs | 4 ++-- PluralKit.Tests/ProxyTagParserTests.cs | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyTagParser.cs b/PluralKit.Bot/Proxy/ProxyTagParser.cs index 733adbb5..a598b030 100644 --- a/PluralKit.Bot/Proxy/ProxyTagParser.cs +++ b/PluralKit.Bot/Proxy/ProxyTagParser.cs @@ -71,10 +71,10 @@ namespace PluralKit.Bot if (!isMatch) return false; // We got a match, extract inner text - inner = input.Substring(prefix.Length, input.Length - prefix.Length - suffix.Length).Trim(); + inner = input.Substring(prefix.Length, input.Length - prefix.Length - suffix.Length); // (see https://github.com/xSke/PluralKit/pull/181) - return inner != "\U0000fe0f"; + return inner.Trim() != "\U0000fe0f"; } private string? ExtractLeadingMention(ref string input) diff --git a/PluralKit.Tests/ProxyTagParserTests.cs b/PluralKit.Tests/ProxyTagParserTests.cs index eafad5c4..21b0a3f7 100644 --- a/PluralKit.Tests/ProxyTagParserTests.cs +++ b/PluralKit.Tests/ProxyTagParserTests.cs @@ -10,9 +10,6 @@ namespace PluralKit.Tests { public class ProxyTagParserTests { - private ProxyTagParser parser = new ProxyTagParser(); - - public class Basics { private ProxyMember[] members = { @@ -44,8 +41,6 @@ namespace PluralKit.Tests [Theory] [InlineData("[text inside]", "text inside")] [InlineData("A:text after", "text after")] - [InlineData("A: space after prefix", "space after prefix")] - [InlineData("[ lots and lots of spaces ]", "lots and lots of spaces")] public void ContentBetweenTagsIsExtracted(string input, string expectedContent) => AssertMatch(members, input, content: expectedContent); @@ -62,6 +57,12 @@ namespace PluralKit.Tests [InlineData("something A:prefix")] public void TagsOnlyMatchAtTheStartAndEnd(string input) => AssertNoMatch(members, input); + + [Theory] + [InlineData("[ text ]", " text ")] + [InlineData("A: text", " text")] + public void WhitespaceInContentShouldNotBeTrimmed(string input, string expectedContent) => + AssertMatch(members, input, content: expectedContent); } public class MentionPrefix