Skip to content

Commit

Permalink
Merge pull request #195 from Altinity/resubmit_pull_123
Browse files Browse the repository at this point in the history
fix corner case when quotes escaped inside quotes
  • Loading branch information
Slach authored Jun 15, 2020
2 parents e2873e6 + fbdc3e3 commit 9022cd3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions spec/scanner_specs.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,26 @@ describe("scanner:", () => {
expect(scanner.toAST()).toEqual(expectedAST);
});
});

describe("AST case 15 (escaped quotes inside quotes)", () => {
let query = "SELECT now() AS t, 'test\\\'value' AS v FROM $table WHERE v=\"test\\\"field\"",
scanner = new Scanner(query);

let expectedAST = {
"root": [],
"select": [
"now() AS t",
"'test\\\'value' AS v"
],
"from": [
"$table"
],
"where": [
"v = \"test\\\"field\""
],
};
it("expects equality", () => {
expect(scanner.toAST()).toEqual(expectedAST);
});
});
});
2 changes: 1 addition & 1 deletion src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let wsRe = "\\s+",
intRe = "\\d+",
powerIntRe = "\\d+e\\d+",
floatRe = "\\d+\\.\\d*|\\d*\\.\\d+|\\d+[eE][-+]\\d+",
stringRe = "('[^']*')|(`[^`]*`)|(\"[^\"]*\")",
stringRe = "('(?:[^'\\\\]|\\\\.)*')|(`(?:[^`\\\\]|\\\\.)*`)|(\"(?:[^\"\\\\]|\\\\.)*\")",
binaryOpRe = "=>|\\|\\||>=|<=|==|!=|<>|->|[-+/%*=<>\\.!]",
statementRe = "\\b(select|from|where|having|order by|group by|limit|format|prewhere|union all)\\b",
joinsRe = "(any inner join|any left join|all inner join|all left join" +
Expand Down

0 comments on commit 9022cd3

Please sign in to comment.