From 65b8c0972746643808d299043fe3cd717b1bc5b1 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Tue, 1 Jan 2019 18:12:51 -0800 Subject: [PATCH] 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" --- src/Discord.Net.Commands/CommandParser.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Commands/CommandParser.cs b/src/Discord.Net.Commands/CommandParser.cs index 49df92a31..96747ae96 100644 --- a/src/Discord.Net.Commands/CommandParser.cs +++ b/src/Discord.Net.Commands/CommandParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Text; @@ -58,6 +58,15 @@ namespace Discord.Commands { if (curPos != endPos) { + // if this character matches the quotation mark of the end of the string + // means that it should be escaped + // but if is not, then there is no reason to escape it then + if (c != matchQuote) + { + // if no reason to escape the next character, then re-add \ to the arg + argBuilder.Append('\\'); + } + argBuilder.Append(c); isEscaping = false; continue;