Skip to content

Commit fceba46

Browse files
authored
Merge pull request #2 from sgress454/sgress454/fleet-31222-update-escape-character-for-sqlite
fix: update escape character for sqlite
2 parents 5211d01 + 94ead6f commit fceba46

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

pegjs/sqlite.pegjs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,26 +2655,11 @@ single_quote_char
26552655
/ escape_char
26562656

26572657
single_char
2658-
= [^'\\] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f]
2658+
= [^'] // remove \0-\x1F\x7f pnCtrl char [^'\\\0-\x1F\x7f]
26592659
/ escape_char
26602660

26612661
escape_char
2662-
= "\\'" { return "\\'"; }
2663-
/ '\\"' { return '\\"'; }
2664-
/ "\\\\" { return "\\\\"; }
2665-
/ "\\/" { return "\\/"; }
2666-
/ "\\b" { return "\b"; }
2667-
/ "\\f" { return "\f"; }
2668-
/ "\\n" { return "\n"; }
2669-
/ "\\r" { return "\r"; }
2670-
/ "\\t" { return "\t"; }
2671-
/ "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit {
2672-
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
2673-
}
2674-
/ "\\" { return "\\"; }
2675-
/ "''" { return "''" }
2676-
/ '""' { return '""' }
2677-
/ '``' { return '``' }
2662+
= "''"
26782663

26792664
line_terminator
26802665
= [\n\r]

test/sqlite.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,12 @@ describe('sqlite', () => {
266266
})
267267
})
268268
it('should support LIKE with ESCAPE', () => {
269-
const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE '\'`
270-
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE '\'`)
269+
const sql = `SELECT * FROM table_name WHERE column_name LIKE '%pattern%' ESCAPE 'x'`
270+
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '%pattern%' ESCAPE 'x'`)
271+
})
272+
it('should allow single backslash without escaping', () => {
273+
const sql = `SELECT * FROM table_name WHERE column_name LIKE '\\_%' ESCAPE '\\'`
274+
expect(getParsedSql(sql)).to.be.equal(`SELECT * FROM "table_name" WHERE "column_name" LIKE '\\_%' ESCAPE '\\'`)
271275
})
272276
it('should support string concatenation in LIKE opts', () => {
273277
const sql = `SELECT * FROM file WHERE path LIKE 'C:' || CHAR(92) || 'Users' || CHAR(92) || 'example.txt'`

0 commit comments

Comments
 (0)