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
19 changes: 2 additions & 17 deletions pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'`)
Comment on lines -269 to +270
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous PR added this test which I thought proved that the desired query would work, but this really just evaluated to ESCAPE ''. Working with escapes can really do your head in! Updating to just show that ESCAPE works with LIKE, and added a separate test for the \' case.

})
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 '\\'`)
})
})