Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/jmespath/src/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class Lexer {
*/
#consumeLiteral(): Token {
const start = this.#position;
const lexeme = this.#consumeUntil('`').replace('\\`', '`');
const lexeme = this.#consumeUntil('`').replaceAll('\\`', '`');
try {
const parsedJson = JSON.parse(lexeme);

Expand Down Expand Up @@ -315,7 +315,7 @@ class Lexer {
*/
#consumeRawStringLiteral(): Token {
const start = this.#position;
const lexeme = this.#consumeUntil(`'`).replace(`\\'`, `'`);
const lexeme = this.#consumeUntil(`'`).replaceAll(`\\'`, `'`);
const tokenLen = this.#position - start;

return {
Expand Down
21 changes: 21 additions & 0 deletions packages/jmespath/tests/unit/compliance/literal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,24 @@ describe('Literal expressions tests', () => {
}
);
});

describe('Escaped delimiters in literals', () => {
it.each([
{
comment: 'Every escaped backtick in a JSON literal is unescaped.',
expression: '`"a\\`b\\`c"`',
expected: 'a`b`c',
},
{
comment: 'Every escaped quote in a raw string literal is unescaped.',
expression: "'a\\'b\\'c'",
expected: "a'b'c",
},
])('$comment', ({ expression, expected }) => {
// Act
const result = search(expression, {});

// Assess
expect(result).toStrictEqual(expected);
});
});