File tree 3 files changed +19
-7
lines changed
3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
var types = require ( 'pg-types' ) ;
10
+ var escape = require ( 'js-string-escape' ) ;
10
11
11
12
//result object returned from query
12
13
//in the 'end' event and also
@@ -75,13 +76,13 @@ Result.prototype.addRow = function(row) {
75
76
76
77
var inlineParser = function ( fieldName , i ) {
77
78
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 ) +
85
86
"'] = " +
86
87
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);" ;
87
88
} ;
Original file line number Diff line number Diff line change 19
19
"main" : " ./lib" ,
20
20
"dependencies" : {
21
21
"buffer-writer" : " 1.0.1" ,
22
+ "js-string-escape" : " 1.0.1" ,
22
23
"packet-reader" : " 0.2.0" ,
23
24
"pg-connection-string" : " 0.1.3" ,
24
25
"pg-pool" : " 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