Fix backward compatibility with escaped leading quote

deb13e9c97dcf724fff3342f69b6ad0f27ca936b

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +11 -2Ignore whitespace
public/scripts/slash-commands/SlashCommandParser.js+11 -2
@@ -566,9 +566,10 @@ export class SlashCommandParser {
566566 * Expects that the current char is taken after testing.
567567 * @param {string|RegExp} sequence Sequence of chars or regex character group that is the symbol.
568568 * @param {number} offset Offset from the current index (won't move the index if offset != 0).
569+ * @param {boolean} escape Whether to escape the symbol with backslashes.
569570 * @returns Whether the next characters are the indicated symbol.
570571 */
571572 testSymbol(sequence, offset = 0, escape = true) {
572573 if (!this.flags[PARSER_FLAG.STRICT_ESCAPING]) return this.testSymbolLooseyGoosey(sequence, offset);
573574 // /echo abc | /echo def
574575 // -> TOAST: abc
@@ -587,7 +588,7 @@ export class SlashCommandParser {
587588 // -> TOAST: *:}* {:
588589 // -> TOAST: *{:* :}
589590 const escapeOffset = this.jumpedEscapeSequence ? -1 : 0;
590591 const escapes = escape ? this.text.slice(this.index + offset + escapeOffset).replace(/^(\\*).*$/s, '$1').length : 0;
591592 const test = (sequence instanceof RegExp) ?
592593 (text) => new RegExp(`^${sequence.source}`).test(text) :
593594 (text) => text.startsWith(sequence)
@@ -1045,6 +1046,9 @@ export class SlashCommandParser {
10451046 /**@type {SlashCommandUnnamedArgumentAssignment}*/
10461047 let assignment = new SlashCommandUnnamedArgumentAssignment();
10471048 assignment.start = this.index;
1049+ if (rawQuotes && this.testEscapedQuote()) {
1050+ this.take(); // discard the escaping backslash
1051+ }
10481052 if (!split && !rawQuotes && this.testQuotedValue()) {
10491053 // if the next bit is a quoted value, take the whole value and gather contents as a list
10501054 assignment.value = this.parseQuotedValue();
@@ -1187,6 +1191,11 @@ export class SlashCommandParser {
11871191 testQuotedValue() {
11881192 return this.testSymbol('"');
11891193 }
1194+
1195+ testEscapedQuote() {
1196+ return this.testSymbol('\\"', 0, false);
1197+ }
1198+
11901199 testQuotedValueEnd() {
11911200 if (this.endOfText) {
11921201 if (this.verifyCommandNames) throw new SlashCommandParserError(`Unexpected end of quoted value at position ${this.index}`, this.text, this.index);