File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -444,7 +444,21 @@ class Client extends EventEmitter {
444
444
445
445
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
446
446
escapeIdentifier ( str ) {
447
- return '"' + str . replace ( / [ " \0 ] / g, '""' ) + '"'
447
+ var escaped = '"'
448
+
449
+ for ( var i = 0 ; i < str . length ; i ++ ) {
450
+ var c = str [ i ]
451
+ if ( c === '"' ) {
452
+ escaped += c + c
453
+ } else if ( c === '\0' ) {
454
+ throw new Error ( "Identifier contains \\0 which is not allowed in PostgreSQL identifiers." ) ;
455
+ } else {
456
+ escaped += c
457
+ }
458
+ }
459
+
460
+ escaped += '"'
461
+ return escaped
448
462
}
449
463
450
464
// Ported from PostgreSQL 9.2.4 source code in src/interfaces/libpq/fe-exec.c
@@ -460,7 +474,7 @@ class Client extends EventEmitter {
460
474
escaped += c + c
461
475
hasBackslash = true
462
476
} else if ( c === '\0' ) {
463
- // Ignore it
477
+ throw new Error ( "Literal contains \\0 which is not allowed in PostgreSQL strings." ) ;
464
478
} else {
465
479
escaped += c
466
480
}
You can’t perform that action at this time.
0 commit comments