File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed
Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 77 */
88
99var types = require ( 'pg-types' ) ;
10+ var escape = require ( 'js-string-escape' ) ;
1011
1112//result object returned from query
1213//in the 'end' event and also
@@ -75,13 +76,13 @@ Result.prototype.addRow = function(row) {
7576
7677var inlineParser = function ( fieldName , i ) {
7778 return "\nthis['" +
78- //fields containing single quotes will break
79- //the evaluated javascript unless they are escaped
80- //see https://github.com/brianc/node-postgres/issues/507
81- //Addendum: However, we need to make sure to replace all
82- //occurences of apostrophes, not just the first one.
83- //See https://github.com/brianc/node-postgres/issues/934
84- fieldName . replace ( / ' / g , "\\'" ) +
79+ // fields containing single quotes will break
80+ // the evaluated javascript unless they are escaped
81+ // see https://github.com/brianc/node-postgres/issues/507
82+ // Addendum: However, we need to make sure to replace all
83+ // occurences of apostrophes, not just the first one.
84+ // See https://github.com/brianc/node-postgres/issues/934
85+ escape ( fieldName ) +
8586 "'] = " +
8687 "rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);" ;
8788} ;
Original file line number Diff line number Diff line change 2020 "dependencies" : {
2121 "buffer-writer" : " 1.0.1" ,
2222 "packet-reader" : " 0.3.1" ,
23+ "js-string-escape" : " 1.0.1" ,
2324 "pg-connection-string" : " 0.1.3" ,
2425 "pg-pool" : " 1.*" ,
2526 "pg-types" : " 1.*" ,
Original file line number Diff line number Diff line change 1+ var pg = require ( './test-helper' ) . pg
2+
3+ var sql = 'SELECT 1 AS "\\\'/*", 2 AS "\\\'*/\n + process.exit(-1)] = null;\n//"'
4+
5+ var client = new pg . Client ( )
6+ client . connect ( )
7+ client . query ( sql , function ( err , res ) {
8+ if ( err ) throw err
9+ client . end ( )
10+ } )
You can’t perform that action at this time.
0 commit comments