Skip to content

Commit 2bb87d0

Browse files
committed
Throw error on \0
1 parent 3ceb90b commit 2bb87d0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/pg/lib/client.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ class Client extends EventEmitter {
444444

445445
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
446446
escapeIdentifier(str) {
447-
return '"' + str.replace(/["\0]/g, '""') + '"'
447+
if (/\0/.test(str)) {
448+
throw new Error("Identifier contains \\0 which is not allowed in PostgreSQL identifiers.")
449+
}
450+
return '"' + str.replace(/"/g, '""') + '"'
448451
}
449452

450453
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
@@ -460,7 +463,7 @@ class Client extends EventEmitter {
460463
escaped += c + c
461464
hasBackslash = true
462465
} else if (c === '\0') {
463-
// Ignore it
466+
throw new Error("Literal contains \\0 which is not allowed in PostgreSQL strings.");
464467
} else {
465468
escaped += c
466469
}

0 commit comments

Comments
 (0)