不要怂,就是干,撸起袖子干!

Commit 7cb7394e by Christian Holm Committed by Jan Aagaard Meier

fix(escape): Escape null character in postgres (#9006)

1 parent f8a98a14
Showing with 13 additions and 0 deletions
......@@ -55,6 +55,11 @@ function escape(val, timeZone, dialect, format) {
// http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS
// http://stackoverflow.com/q/603572/130598
val = val.replace(/'/g, "''");
if (dialect === 'postgres') {
// null character is not allowed in Postgres
val = val.replace(/\0/g, '\\0');
}
} else {
val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, s => {
switch (s) {
......
......@@ -68,6 +68,14 @@ suite(Support.getTestDialectTeaser('SQL'), () => {
default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)",
mssql: "WHERE [name] = N'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
});
testsql({
name: 'here is a null char: \0'
}, {
default: "WHERE [name] = 'here is a null char: \\0'",
mssql: "WHERE [name] = N'here is a null char: \0'",
sqlite: "WHERE `name` = 'here is a null char: \0'"
});
});
suite('whereItemQuery', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!