Don't trim inner string when matching proxy tags

This commit is contained in:
Ske 2020-06-24 17:19:01 +02:00
parent 178e256583
commit 0ee22813fa
2 changed files with 8 additions and 7 deletions

View File

@ -71,10 +71,10 @@ namespace PluralKit.Bot
if (!isMatch) return false; if (!isMatch) return false;
// We got a match, extract inner text // 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) // (see https://github.com/xSke/PluralKit/pull/181)
return inner != "\U0000fe0f"; return inner.Trim() != "\U0000fe0f";
} }
private string? ExtractLeadingMention(ref string input) private string? ExtractLeadingMention(ref string input)

View File

@ -10,9 +10,6 @@ namespace PluralKit.Tests
{ {
public class ProxyTagParserTests public class ProxyTagParserTests
{ {
private ProxyTagParser parser = new ProxyTagParser();
public class Basics public class Basics
{ {
private ProxyMember[] members = { private ProxyMember[] members = {
@ -44,8 +41,6 @@ namespace PluralKit.Tests
[Theory] [Theory]
[InlineData("[text inside]", "text inside")] [InlineData("[text inside]", "text inside")]
[InlineData("A:text after", "text after")] [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) => public void ContentBetweenTagsIsExtracted(string input, string expectedContent) =>
AssertMatch(members, input, content: expectedContent); AssertMatch(members, input, content: expectedContent);
@ -62,6 +57,12 @@ namespace PluralKit.Tests
[InlineData("something A:prefix")] [InlineData("something A:prefix")]
public void TagsOnlyMatchAtTheStartAndEnd(string input) => public void TagsOnlyMatchAtTheStartAndEnd(string input) =>
AssertNoMatch(members, 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 public class MentionPrefix