Skip to content

Commit

Permalink
escape backslashes last
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimkibana committed Jan 7, 2025
1 parent 9d95a80 commit cdeec72
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,42 @@ describe('literal expression', () => {
],
});
});

it('escape double-quote before backslash', () => {
const text = `ROW "a\\"\\\\b", 1`;
const { root } = parse(text);

expect(root.commands[0]).toMatchObject({
type: 'command',
args: [
{
type: 'literal',
literalType: 'keyword',
name: '"a\\"\\\\b"',
valueUnquoted: 'a"\\b',
},
{},
],
});
});

it('escape backslash before double-quote', () => {
const text = `ROW "a\\\\\\"b", 1`;
const { root } = parse(text);

expect(root.commands[0]).toMatchObject({
type: 'command',
args: [
{
type: 'literal',
literalType: 'keyword',
name: '"a\\\\\\"b"',
valueUnquoted: 'a\\"b',
},
{},
],
});
});
});

describe('triple quoted', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ export function createLiteralString(ctx: StringContext): ESQLLiteral {

if (!isTripleQuoted) {
valueUnquoted = valueUnquoted
.replace(/\\\\/g, '\\')
.replace(/\\"/g, '"')
.replace(/\\r/g, '\r')
.replace(/\\n/g, '\n')
.replace(/\\t/g, '\t');
.replace(/\\t/g, '\t')
.replace(/\\\\/g, '\\');
}

return Builder.expression.literal.string(
Expand Down

0 comments on commit cdeec72

Please sign in to comment.