Fix backward compatibility with escaped leading quote
| @@ -566,9 +566,10 @@ export class SlashCommandParser { | |||
| 566 | * Expects that the current char is taken after testing. | 566 | * Expects that the current char is taken after testing. |
| 567 | * @param {string|RegExp} sequence Sequence of chars or regex character group that is the symbol. | 567 | * @param {string|RegExp} sequence Sequence of chars or regex character group that is the symbol. |
| 568 | * @param {number} offset Offset from the current index (won't move the index if offset != 0). | 568 | * @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. | ||
| 569 | * @returns Whether the next characters are the indicated symbol. | 570 | * @returns Whether the next characters are the indicated symbol. |
| 570 | */ | 571 | */ |
| 571 | testSymbol(sequence, offset = 0) { | 572 | testSymbol(sequence, offset = 0, escape = true) { |
| 572 | if (!this.flags[PARSER_FLAG.STRICT_ESCAPING]) return this.testSymbolLooseyGoosey(sequence, offset); | 573 | if (!this.flags[PARSER_FLAG.STRICT_ESCAPING]) return this.testSymbolLooseyGoosey(sequence, offset); |
| 573 | // /echo abc | /echo def | 574 | // /echo abc | /echo def |
| 574 | // -> TOAST: abc | 575 | // -> TOAST: abc |
| @@ -587,7 +588,7 @@ export class SlashCommandParser { | |||
| 587 | // -> TOAST: *:}* {: | 588 | // -> TOAST: *:}* {: |
| 588 | // -> TOAST: *{:* :} | 589 | // -> TOAST: *{:* :} |
| 589 | const escapeOffset = this.jumpedEscapeSequence ? -1 : 0; | 590 | const escapeOffset = this.jumpedEscapeSequence ? -1 : 0; |
| 590 | const escapes = this.text.slice(this.index + offset + escapeOffset).replace(/^(\\*).*$/s, '$1').length; | 591 | const escapes = escape ? this.text.slice(this.index + offset + escapeOffset).replace(/^(\\*).*$/s, '$1').length : 0; |
| 591 | const test = (sequence instanceof RegExp) ? | 592 | const test = (sequence instanceof RegExp) ? |
| 592 | (text) => new RegExp(`^${sequence.source}`).test(text) : | 593 | (text) => new RegExp(`^${sequence.source}`).test(text) : |
| 593 | (text) => text.startsWith(sequence) | 594 | (text) => text.startsWith(sequence) |
| @@ -1045,6 +1046,9 @@ export class SlashCommandParser { | |||
| 1045 | /**@type {SlashCommandUnnamedArgumentAssignment}*/ | 1046 | /**@type {SlashCommandUnnamedArgumentAssignment}*/ |
| 1046 | let assignment = new SlashCommandUnnamedArgumentAssignment(); | 1047 | let assignment = new SlashCommandUnnamedArgumentAssignment(); |
| 1047 | assignment.start = this.index; | 1048 | assignment.start = this.index; |
| 1049 | if (rawQuotes && this.testEscapedQuote()) { | ||
| 1050 | this.take(); // discard the escaping backslash | ||
| 1051 | } | ||
| 1048 | if (!split && !rawQuotes && this.testQuotedValue()) { | 1052 | if (!split && !rawQuotes && this.testQuotedValue()) { |
| 1049 | // if the next bit is a quoted value, take the whole value and gather contents as a list | 1053 | // if the next bit is a quoted value, take the whole value and gather contents as a list |
| 1050 | assignment.value = this.parseQuotedValue(); | 1054 | assignment.value = this.parseQuotedValue(); |
| @@ -1187,6 +1191,11 @@ export class SlashCommandParser { | |||
| 1187 | testQuotedValue() { | 1191 | testQuotedValue() { |
| 1188 | return this.testSymbol('"'); | 1192 | return this.testSymbol('"'); |
| 1189 | } | 1193 | } |
| 1194 | |||
| 1195 | testEscapedQuote() { | ||
| 1196 | return this.testSymbol('\\"', 0, false); | ||
| 1197 | } | ||
| 1198 | |||
| 1190 | testQuotedValueEnd() { | 1199 | testQuotedValueEnd() { |
| 1191 | if (this.endOfText) { | 1200 | if (this.endOfText) { |
| 1192 | if (this.verifyCommandNames) throw new SlashCommandParserError(`Unexpected end of quoted value at position ${this.index}`, this.text, this.index); | 1201 | if (this.verifyCommandNames) throw new SlashCommandParserError(`Unexpected end of quoted value at position ${this.index}`, this.text, this.index); |