Skip to content

Commit 65b8c09

Browse files
Chris-Johnstonfoxbot
authored andcommitted
fix: Only escape the closing quotation mark of non-remainder strings (#1226)
Before this change, non-remainder string arguments like @"test \n" would escape the character 'n', even though there is no reason to. For the purposes of the command parser, the only character(s) that can be escaped is the closing quotation mark (typically '"'). This change only removes the backslash character from the resulting argument if it matches the closing quotation mark. This change does not affect remainder parameters. For example: @"`\\test`" now results in @"`\\test`", not @"`\test`" @"test \n" results in @"test \n", not "test n"
1 parent d39bf6e commit 65b8c09

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Discord.Net.Commands/CommandParser.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
44
using System.Text;
@@ -58,6 +58,15 @@ char GetMatch(IReadOnlyDictionary<char, char> dict, char ch)
5858
{
5959
if (curPos != endPos)
6060
{
61+
// if this character matches the quotation mark of the end of the string
62+
// means that it should be escaped
63+
// but if is not, then there is no reason to escape it then
64+
if (c != matchQuote)
65+
{
66+
// if no reason to escape the next character, then re-add \ to the arg
67+
argBuilder.Append('\\');
68+
}
69+
6170
argBuilder.Append(c);
6271
isEscaping = false;
6372
continue;

0 commit comments

Comments
 (0)