Skip to content

Commit

Permalink
fix: Only escape the closing quotation mark of non-remainder strings (#…
Browse files Browse the repository at this point in the history
…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"
  • Loading branch information
Chris-Johnston authored and foxbot committed Jan 2, 2019
1 parent d39bf6e commit 65b8c09
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Discord.Net.Commands/CommandParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;
Expand Down Expand Up @@ -58,6 +58,15 @@ char GetMatch(IReadOnlyDictionary<char, char> dict, char ch)
{
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;
Expand Down

0 comments on commit 65b8c09

Please sign in to comment.