diff --git a/pegjs/sqlite.pegjs b/pegjs/sqlite.pegjs index ab6a1b9d..2a08248b 100644 --- a/pegjs/sqlite.pegjs +++ b/pegjs/sqlite.pegjs @@ -2634,26 +2634,11 @@ single_quote_char / escape_char single_char - = [^'\\] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f] + = [^'] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f] / escape_char escape_char - = "\\'" { return "\\'"; } - / '\\"' { return '\\"'; } - / "\\\\" { return "\\\\"; } - / "\\/" { return "\\/"; } - / "\\b" { return "\b"; } - / "\\f" { return "\f"; } - / "\\n" { return "\n"; } - / "\\r" { return "\r"; } - / "\\t" { return "\t"; } - / "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit { - return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); - } - / "\\" { return "\\"; } - / "''" { return "''" } - / '""' { return '""' } - / '``' { return '``' } + = "''" line_terminator = [\n\r] diff --git a/test/sqlite.spec.js b/test/sqlite.spec.js index dda7d384..3933684f 100644 --- a/test/sqlite.spec.js +++ b/test/sqlite.spec.js @@ -266,7 +266,11 @@ describe('sqlite', () => { }) }) it('should support LIKE with ESCAPE', () => { - const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE '\'` - expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE '\'`) + const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE 'x'` + expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE 'x'`) + }) + it('should allow single backslash without escaping', () => { + const sql = `SELECT * FROM table_name WHERE column_name LIKE '\\_%' ESCAPE '\\'` + expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '\\_%' ESCAPE '\\'`) }) })