Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.1.5
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.1.6
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 12, 2017

  1. Fix vulnerability

    brianc committed Aug 12, 2017
    Copy the full SHA
    c0a381e View commit details
  2. Bump version

    brianc committed Aug 12, 2017
    Copy the full SHA
    b0a2fe4 View commit details
Showing with 20 additions and 8 deletions.
  1. +8 −7 lib/result.js
  2. +2 −1 package.json
  3. +10 −0 test/integration/client/field-name-escape-tests.js
15 changes: 8 additions & 7 deletions lib/result.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
*/

var types = require('pg-types');
var escape = require('js-string-escape');

//result object returned from query
//in the 'end' event and also
@@ -75,13 +76,13 @@ Result.prototype.addRow = function(row) {

var inlineParser = function(fieldName, i) {
return "\nthis['" +
//fields containing single quotes will break
//the evaluated javascript unless they are escaped
//see https://github.com/brianc/node-postgres/issues/507
//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
fieldName.replace(/'/g, "\\'") +
// fields containing single quotes will break
// the evaluated javascript unless they are escaped
// see https://github.com/brianc/node-postgres/issues/507
// 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 + "]);";
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "6.1.5",
"version": "6.1.6",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"postgres",
@@ -19,6 +19,7 @@
"main": "./lib",
"dependencies": {
"buffer-writer": "1.0.1",
"js-string-escape": "1.0.1",
"packet-reader": "0.2.0",
"pg-connection-string": "0.1.3",
"pg-pool": "1.*",
10 changes: 10 additions & 0 deletions test/integration/client/field-name-escape-tests.js
Original file line number Diff line number Diff line change
@@ -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()
})