mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
068a65ee6c | ||
|
|
38de09db6f |
@ -1,4 +1,5 @@
|
|||||||
var types = require('pg-types');
|
var types = require('pg-types');
|
||||||
|
var escape = require('js-string-escape');
|
||||||
|
|
||||||
//result object returned from query
|
//result object returned from query
|
||||||
//in the 'end' event and also
|
//in the 'end' event and also
|
||||||
@ -70,7 +71,10 @@ var inlineParser = function(fieldName, i) {
|
|||||||
// fields containing single quotes will break
|
// fields containing single quotes will break
|
||||||
// the evaluated javascript unless they are escaped
|
// the evaluated javascript unless they are escaped
|
||||||
// see https://github.com/brianc/node-postgres/issues/507
|
// see https://github.com/brianc/node-postgres/issues/507
|
||||||
fieldName.replace("'", "\\'") +
|
// Addendum: However, we need to make sure to replace all
|
||||||
|
// occurences of apostrophes, not just the first one.
|
||||||
|
// See https://github.com/brianc/node-postgres/issues/934
|
||||||
|
escape(fieldName) +
|
||||||
"'] = " +
|
"'] = " +
|
||||||
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
|
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "pg",
|
"name": "pg",
|
||||||
"version": "3.6.3",
|
"version": "3.6.4",
|
||||||
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
"description": "PostgreSQL client - pure javascript & libpq with the same API",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"postgres",
|
"postgres",
|
||||||
@ -21,6 +21,7 @@
|
|||||||
"bindings": "1.2.1",
|
"bindings": "1.2.1",
|
||||||
"buffer-writer": "1.0.0",
|
"buffer-writer": "1.0.0",
|
||||||
"generic-pool": "2.1.1",
|
"generic-pool": "2.1.1",
|
||||||
|
"js-string-escape": "1.0.1",
|
||||||
"nan": "1.3.0",
|
"nan": "1.3.0",
|
||||||
"packet-reader": "0.2.0",
|
"packet-reader": "0.2.0",
|
||||||
"pg-connection-string": "0.1.3",
|
"pg-connection-string": "0.1.3",
|
||||||
|
|||||||
10
test/integration/client/field-name-escape-tests.js
Normal file
10
test/integration/client/field-name-escape-tests.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
var pg = require('./test-helper').pg
|
||||||
|
|
||||||
|
var sql = 'SELECT 1 AS "\\\'/*", 2 AS "\\\'*/\n + process.exit(-1)] = null;\n//"'
|
||||||
|
|
||||||
|
var client = new pg.Client()
|
||||||
|
client.connect()
|
||||||
|
client.query(sql, function (err, res) {
|
||||||
|
if (err) throw err
|
||||||
|
client.end()
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user