diff --git a/.travis.yml b/.travis.yml index 74f1e4c0c..d4820080f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,44 +1,37 @@ language: node_js -sudo: false -dist: trusty -before_script: - - node script/create-test-tables.js pg://postgres@127.0.0.1:5432/postgres + env: - - CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres + global: + - CC=clang CXX=clang++ npm_config_clang=1 PGUSER=postgres PGDATABASE=postgres +jobs: + include: + - env: POSTGRESQL_VERSION="9.6" + dist: xenial + node_js: 10 + - env: POSTGRESQL_VERSION="10" + dist: xenial + node_js: 10 + - env: POSTGRESQL_VERSION="11" + dist: xenial + node_js: 10 + - env: POSTGRESQL_VERSION="11" + dist: xenial + node_js: 12 + - env: POSTGRESQL_VERSION="12" + dist: bionic + node_js: 10 + - env: POSTGRESQL_VERSION="12" + dist: bionic + node_js: 12 -node_js: "6" -addons: - postgresql: "9.6" +before_install: + - sudo service postgresql stop; + - sudo apt-get remove postgresql* -y + - sudo apt-get install -y --allow-unauthenticated --no-install-recommends --no-install-suggests postgresql-$POSTGRESQL_VERSION postgresql-client-$POSTGRESQL_VERSION postgresql-server-dev-$POSTGRESQL_VERSION postgresql-common + - sudo pg_dropcluster --stop $POSTGRESQL_VERSION main + - sudo rm -rf /etc/postgresql/$POSTGRESQL_VERSION /var/lib/postgresql/$POSTGRESQL_VERSION + - sudo pg_createcluster -u postgres $POSTGRESQL_VERSION main -- -A trust + - sudo /etc/init.d/postgresql start $POSTGRESQL_VERSION || sudo journalctl -xe -matrix: - include: - - node_js: "0.10" - addons: - postgresql: "9.6" - env: [] - - node_js: "0.12" - addons: - postgresql: "9.6" - env: [] - - node_js: "4" - addons: - postgresql: "9.6" - - node_js: "5" - addons: - postgresql: "9.6" - - node_js: "6" - addons: - postgresql: "9.1" - dist: precise - - node_js: "6" - addons: - postgresql: "9.2" - - node_js: "6" - addons: - postgresql: "9.3" - - node_js: "6" - addons: - postgresql: "9.4" - - node_js: "6" - addons: - postgresql: "9.5" +before_script: + - node script/create-test-tables.js pg://postgres@127.0.0.1:$PGPORT/postgres diff --git a/CHANGELOG.carto.md b/CHANGELOG.carto.md new file mode 100644 index 000000000..56ea9c495 --- /dev/null +++ b/CHANGELOG.carto.md @@ -0,0 +1,10 @@ +# CARTO's changelog + +## 6.4.2-cdb3 +2018-mm-dd + +## 6.4.2-cdb2 +2018-11-20 + +- Support Node.js 10 +- Add package-lock.json diff --git a/Makefile b/Makefile index 4eddd4f10..a6f7b7968 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ test: test-unit test-all: jshint test-missing-native test-unit test-integration test-native test-binary +test-all-nonative: jshint test-unit test-integration test-binary update-npm: @npm i npm --global diff --git a/lib/client.js b/lib/client.js index a031eb3e3..fa3716cd2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -161,6 +161,10 @@ Client.prototype.connect = function(callback) { self.emit('notification', msg); }); + con.on('maxRowSize', function (msg) { + self.emit('maxRowSize', msg); + }); + //process possible callback argument to Client#connect if (callback) { callback(null, self); diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index e6efa158e..44d10f636 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -60,6 +60,7 @@ var ConnectionParameters = function(config) { this.replication = val("replication", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); + this.keepAlive = config.keepAlive || false; this.application_name = val('application_name', config, 'PGAPPNAME'); this.fallback_application_name = val('fallback_application_name', config, false); diff --git a/lib/connection.js b/lib/connection.js index 0fb874cf5..d94de03d9 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -10,6 +10,8 @@ var net = require('net'); var EventEmitter = require('events').EventEmitter; var util = require('util'); +var defaults = require('./defaults'); + var Writer = require('buffer-writer'); var Reader = require('packet-reader'); @@ -534,6 +536,10 @@ var DataRowMessage = function(length, fieldCount) { //extremely hot-path code Connection.prototype.parseD = function(buffer, length) { + if (Number.isFinite(defaults.maxRowSize) && length > defaults.maxRowSize) { + return new Message('maxRowSize', length); + } + var fieldCount = this.parseInt16(buffer); var msg = new DataRowMessage(length, fieldCount); for(var i = 0; i < fieldCount; i++) { diff --git a/lib/index.js b/lib/index.js index 17abb5bc8..a2c2792f4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,7 +27,7 @@ var PG = function(clientConstructor) { util.inherits(PG, EventEmitter); -PG.prototype.end = util.deprecate(function() { +PG.prototype.end = function() { var self = this; var keys = Object.keys(this._pools); var count = keys.length; @@ -47,9 +47,9 @@ PG.prototype.end = util.deprecate(function() { }); }); } -}, 'PG.end is deprecated - please see the upgrade guide at https://node-postgres.com/guides/upgrading'); +}; -PG.prototype.connect = util.deprecate(function(config, callback) { +PG.prototype.connect = function(config, callback) { if(typeof config == "function") { callback = config; config = null; @@ -75,10 +75,10 @@ PG.prototype.connect = util.deprecate(function(config, callback) { }.bind(this)); } return pool.connect(callback); -}, 'PG.connect is deprecated - please see the upgrade guide at https://node-postgres.com/guides/upgrading'); +}; // cancel the query running on the given client -PG.prototype.cancel = util.deprecate(function(config, client, query) { +PG.prototype.cancel = function(config, client, query) { if(client.native) { return client.cancel(query); } @@ -89,7 +89,7 @@ PG.prototype.cancel = util.deprecate(function(config, client, query) { } var cancellingClient = new this.Client(c); cancellingClient.cancel(client, query); -}, 'PG.cancel is deprecated - use client.cancel instead'); +}; if(typeof process.env.NODE_PG_FORCE_NATIVE != 'undefined') { module.exports = new PG(require('./native')); diff --git a/lib/native/query.js b/lib/native/query.js index 88e19f5f9..214488f60 100644 --- a/lib/native/query.js +++ b/lib/native/query.js @@ -68,9 +68,9 @@ NativeQuery.prototype._getPromise = function() { return this._promise; }; -NativeQuery.prototype.promise = util.deprecate(function() { +NativeQuery.prototype.promise = function() { return this._getPromise(); -}, 'Query.promise() is deprecated - see the upgrade guide at https://node-postgres.com/guides/upgrading'); +}; NativeQuery.prototype.handleError = function(err) { var self = this; diff --git a/lib/query.js b/lib/query.js index b8f6d77eb..e9c3d1560 100644 --- a/lib/query.js +++ b/lib/query.js @@ -73,9 +73,9 @@ Query.prototype._getPromise = function () { return this._promise; }; -Query.prototype.promise = util.deprecate(function() { +Query.prototype.promise = function() { return this._getPromise(); -}, 'Query.promise() is deprecated - see the upgrade guide at https://node-postgres.com/guides/upgrading'); +}; Query.prototype.requiresPreparation = function() { //named queries must always be prepared diff --git a/lib/result.js b/lib/result.js index 093a73c37..fbf98cdf9 100644 --- a/lib/result.js +++ b/lib/result.js @@ -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 + "]);"; }; diff --git a/lib/utils.js b/lib/utils.js index 56a45cb06..cd3ee2ef8 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -142,7 +142,6 @@ function normalizeQueryConfig (config, values, callback) { return config; } -var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated and will be removed in pg@7.0. Please see the upgrade guide at https://node-postgres.com/guides/upgrading'; var deprecateEventEmitter = function(Emitter) { var Result = function () { @@ -151,8 +150,8 @@ var deprecateEventEmitter = function(Emitter) { util.inherits(Result, Emitter); Result.prototype._on = Result.prototype.on; Result.prototype._once = Result.prototype.once; - Result.prototype.on = util.deprecate(Result.prototype.on, queryEventEmitterOverloadDeprecationMessage); - Result.prototype.once = util.deprecate(Result.prototype.once, queryEventEmitterOverloadDeprecationMessage); + Result.prototype.on = Result.prototype.on; + Result.prototype.once = Result.prototype.once; return Result; }; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..a001c9f29 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,361 @@ +{ + "name": "pg", + "version": "6.4.2-cdb3", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "async": { + "version": "0.9.0", + "resolved": "http://registry.npmjs.org/async/-/async-0.9.0.tgz", + "integrity": "sha1-rDYTsdqb7RtHUQu0ZRuJMeRxRsc=", + "dev": true + }, + "buffer-writer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz", + "integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg=" + }, + "cli": { + "version": "0.6.6", + "resolved": "https://registry.npmjs.org/cli/-/cli-0.6.6.tgz", + "integrity": "sha1-Aq1Eo4Cr8nraxebwzdewQ9dMU+M=", + "dev": true, + "requires": { + "exit": "0.1.2", + "glob": "~ 3.2.1" + } + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", + "dev": true + }, + "console-browserify": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", + "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", + "dev": true, + "requires": { + "date-now": "^0.1.4" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "dev": true + }, + "date-now": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", + "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", + "dev": true + }, + "dom-serializer": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.0.tgz", + "integrity": "sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=", + "dev": true, + "requires": { + "domelementtype": "~1.1.1", + "entities": "~1.1.1" + }, + "dependencies": { + "domelementtype": { + "version": "1.1.3", + "resolved": "http://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", + "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=", + "dev": true + }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", + "dev": true + } + } + }, + "domelementtype": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.2.1.tgz", + "integrity": "sha512-SQVCLFS2E7G5CRCMdn6K9bIhRj1bS6QBWZfF0TUPh4V/BbqrQ619IdSS3/izn0FZ+9l+uODzaZjb08fjOfablA==", + "dev": true + }, + "domhandler": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.2.1.tgz", + "integrity": "sha1-Wd+dzSJ+gIs2Wuc+H2aErD2Ub8I=", + "dev": true, + "requires": { + "domelementtype": "1" + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "dev": true, + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, + "entities": { + "version": "1.0.0", + "resolved": "http://registry.npmjs.org/entities/-/entities-1.0.0.tgz", + "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=", + "dev": true + }, + "exit": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz", + "integrity": "sha1-BjJjj42HfMghB9MKD/8aF8uhzQw=", + "dev": true + }, + "generic-pool": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-2.4.3.tgz", + "integrity": "sha1-eAw29p360FpaBF3Te+etyhGk9v8=" + }, + "glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", + "dev": true, + "requires": { + "inherits": "2", + "minimatch": "0.3" + }, + "dependencies": { + "minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + } + } + }, + "htmlparser2": { + "version": "3.7.3", + "resolved": "http://registry.npmjs.org/htmlparser2/-/htmlparser2-3.7.3.tgz", + "integrity": "sha1-amTHdjfAjG8w7CqBV6UzM758sF4=", + "dev": true, + "requires": { + "domelementtype": "1", + "domhandler": "2.2", + "domutils": "1.5", + "entities": "1.0", + "readable-stream": "1.1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, + "js-string-escape": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz", + "integrity": "sha1-4mJbrbwNZ8dTPp7cEGjFh65BN+8=" + }, + "jshint": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.5.2.tgz", + "integrity": "sha1-vsIj1RSeSe9uqW3PizUEonYT6L4=", + "dev": true, + "requires": { + "cli": "0.6.x", + "console-browserify": "1.1.x", + "exit": "0.1.x", + "htmlparser2": "3.7.x", + "minimatch": "0.x.x", + "shelljs": "0.3.x", + "strip-json-comments": "0.1.x", + "underscore": "1.6.x" + } + }, + "lodash": { + "version": "4.13.1", + "resolved": "http://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz", + "integrity": "sha1-g+SxCRP0hJbU0W/sSlYK8u50S2g=", + "dev": true + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.4.0.tgz", + "integrity": "sha1-vSx9Bg0sjI/Xzefx8u0tWycP2xs=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + }, + "object-assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.0.tgz", + "integrity": "sha1-ejs9DpgGPUP0wD8uiubNUahog6A=" + }, + "packet-reader": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz", + "integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc=" + }, + "pg-connection-string": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz", + "integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=" + }, + "pg-copy-streams": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/pg-copy-streams/-/pg-copy-streams-0.3.0.tgz", + "integrity": "sha1-pPvCo7eI1Onab3fOs1Qi2NcEO38=", + "dev": true + }, + "pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" + }, + "pg-pool": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-1.8.0.tgz", + "integrity": "sha1-9+xzgkw3oD8Hb1G/33DjQBR8Tzc=", + "requires": { + "generic-pool": "2.4.3", + "object-assign": "4.1.0" + } + }, + "pg-types": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz", + "integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==", + "requires": { + "pg-int8": "1.0.1", + "postgres-array": "~1.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.0", + "postgres-interval": "^1.1.0" + } + }, + "pgpass": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz", + "integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=", + "requires": { + "split": "^1.0.0" + } + }, + "postgres-array": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.3.tgz", + "integrity": "sha512-5wClXrAP0+78mcsNX3/ithQ5exKvCyK5lr5NEEEeGwwM6NJdQgzIJBVxLvRW+huFpX92F2QnZ5CcokH0VhK2qQ==" + }, + "postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=" + }, + "postgres-date": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz", + "integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g=" + }, + "postgres-interval": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.1.2.tgz", + "integrity": "sha512-fC3xNHeTskCxL1dC8KOtxXt7YeFmlbTYtn7ul8MkVERuTmf7pI4DrkAxcw3kh1fQ9uz4wQmd03a1mRiXUZChfQ==", + "requires": { + "xtend": "^4.0.0" + } + }, + "promise-polyfill": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-5.2.1.tgz", + "integrity": "sha1-u61wTnbJgMGW2vJhytRk/L1NdaQ=", + "dev": true + }, + "readable-stream": { + "version": "1.1.14", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", + "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.1", + "isarray": "0.0.1", + "string_decoder": "~0.10.x" + } + }, + "semver": { + "version": "4.3.2", + "resolved": "http://registry.npmjs.org/semver/-/semver-4.3.2.tgz", + "integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=" + }, + "shelljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", + "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "split": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", + "integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==", + "requires": { + "through": "2" + } + }, + "string_decoder": { + "version": "0.10.31", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", + "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "dev": true + }, + "strip-json-comments": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-0.1.3.tgz", + "integrity": "sha1-Fkxk43Coo8wAyeAbU55WmCPw7lQ=", + "dev": true + }, + "through": { + "version": "2.3.8", + "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" + }, + "underscore": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz", + "integrity": "sha1-izixDKze9jM3uLJOT/htRa6lKag=", + "dev": true + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + } + } +} diff --git a/package.json b/package.json index 7bd05f7f4..c40269b12 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg", - "version": "6.4.1", + "version": "6.4.2-cdb3", "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.3.1", "pg-connection-string": "0.1.3", "pg-pool": "1.*", @@ -37,7 +38,7 @@ "minNativeVersion": "1.7.0", "scripts": { "changelog": "npm i github-changes && ./node_modules/.bin/github-changes -o brianc -r node-postgres -d pulls -a -v", - "test": "make test-all connectionString=postgres://postgres@localhost:5432/postgres" + "test": "make test-all-nonative connectionString=postgres://postgres@localhost:$PGPORT/postgres" }, "license": "MIT", "engines": { diff --git a/test/cli.js b/test/cli.js index bec0f3fb3..8672473f0 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,10 +1,15 @@ var ConnectionParameters = require(__dirname + '/../lib/connection-parameters'); var config = new ConnectionParameters(process.argv[2]); +var semver = require('semver') for(var i = 0; i < process.argv.length; i++) { switch(process.argv[i].toLowerCase()) { case 'native': - config.native = true; + if (semver.gte(process.version, '4.0.0')) { + config.native = true; + } else { + console.log('Not running native in node < v4.0.0') + } break; case 'binary': config.binary = true; diff --git a/test/integration/client/deprecation-tests.js b/test/integration/client/deprecation-tests.js index 21decc46f..41a1e3256 100644 --- a/test/integration/client/deprecation-tests.js +++ b/test/integration/client/deprecation-tests.js @@ -2,6 +2,7 @@ var helper = require('./test-helper') process.on('warning', function (warning) { console.log(warning) + if (warning.message.startsWith('Buffer() is deprecated')) return throw new Error('Should not emit deprecation warning') }) diff --git a/test/integration/client/field-name-escape-tests.js b/test/integration/client/field-name-escape-tests.js new file mode 100644 index 000000000..146ad1b68 --- /dev/null +++ b/test/integration/client/field-name-escape-tests.js @@ -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() +}) diff --git a/test/integration/client/json-type-parsing-tests.js b/test/integration/client/json-type-parsing-tests.js index 1c0759bf3..d216aef48 100644 --- a/test/integration/client/json-type-parsing-tests.js +++ b/test/integration/client/json-type-parsing-tests.js @@ -9,7 +9,7 @@ if (helper.config.binary) { test('can read and write json', function() { helper.pg.connect(helper.config, function(err, client, done) { assert.ifError(err); - helper.versionGTE(client, '9.2.0', assert.success(function(jsonSupported) { + helper.versionGTE(client, '90200', assert.success(function(jsonSupported) { if(!jsonSupported) { console.log('skip json test on older versions of postgres'); done(); diff --git a/test/integration/client/query-error-handling-prepared-statement-tests.js b/test/integration/client/query-error-handling-prepared-statement-tests.js index 77615ff3a..c9bb260db 100644 --- a/test/integration/client/query-error-handling-prepared-statement-tests.js +++ b/test/integration/client/query-error-handling-prepared-statement-tests.js @@ -6,7 +6,7 @@ function killIdleQuery(targetQuery) { var pidColName = 'procpid' var queryColName = 'current_query'; client2.connect(assert.success(function() { - helper.versionGTE(client2, '9.2.0', assert.success(function(isGreater) { + helper.versionGTE(client2, '90200', assert.success(function(isGreater) { if(isGreater) { pidColName = 'pid'; queryColName = 'query'; diff --git a/test/integration/client/query-error-handling-tests.js b/test/integration/client/query-error-handling-tests.js index 2618a49df..e7bd56a58 100644 --- a/test/integration/client/query-error-handling-tests.js +++ b/test/integration/client/query-error-handling-tests.js @@ -7,7 +7,7 @@ test('error during query execution', function() { var sleepQuery = 'select pg_sleep(5)'; var pidColName = 'procpid' var queryColName = 'current_query'; - helper.versionGTE(client, '9.2.0', assert.success(function(isGreater) { + helper.versionGTE(client, 90200, assert.success(function(isGreater) { if(isGreater) { pidColName = 'pid'; queryColName = 'query'; @@ -43,7 +43,7 @@ if(helper.config.native) return; test('9.3 column error fields', function() { var client = new Client(helper.args); client.connect(assert.success(function() { - helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) { + helper.versionGTE(client, 90300, assert.success(function(isGreater) { if(!isGreater) { return client.end(); } @@ -65,7 +65,7 @@ test('9.3 column error fields', function() { test('9.3 constraint error fields', function() { var client = new Client(helper.args); client.connect(assert.success(function() { - helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) { + helper.versionGTE(client, 90300, assert.success(function(isGreater) { if(!isGreater) { console.log('skip 9.3 error field on older versions of postgres'); return client.end(); diff --git a/test/integration/client/result-metadata-tests.js b/test/integration/client/result-metadata-tests.js index 013630033..b9d09b5d3 100644 --- a/test/integration/client/result-metadata-tests.js +++ b/test/integration/client/result-metadata-tests.js @@ -5,7 +5,7 @@ test('should return insert metadata', function() { pg.connect(helper.config, assert.calls(function(err, client, done) { assert.isNull(err); - helper.versionGTE(client, '9.0.0', assert.success(function(hasRowCount) { + helper.versionGTE(client, '90000', assert.success(function(hasRowCount) { client.query("CREATE TEMP TABLE zugzug(name varchar(10))", assert.calls(function(err, result) { assert.isNull(err); assert.equal(result.oid, null); diff --git a/test/integration/connection-pool/error-tests.js b/test/integration/connection-pool/error-tests.js index 59121a86e..27525bf08 100644 --- a/test/integration/connection-pool/error-tests.js +++ b/test/integration/connection-pool/error-tests.js @@ -11,7 +11,7 @@ pg.connect(helper.config, assert.success(function(client, done) { pg.connect(helper.config, assert.success(function(client2, done2) { client2.id = 2; var pidColName = 'procpid'; - helper.versionGTE(client2, '9.2.0', assert.success(function(isGreater) { + helper.versionGTE(client2, '90200', assert.success(function(isGreater) { var killIdleQuery = 'SELECT pid, (SELECT pg_terminate_backend(pid)) AS killed FROM pg_stat_activity WHERE state = $1'; var params = ['idle']; if(!isGreater) { diff --git a/test/integration/test-helper.js b/test/integration/test-helper.js index c6a4922dc..155c36077 100644 --- a/test/integration/test-helper.js +++ b/test/integration/test-helper.js @@ -13,14 +13,13 @@ helper.client = function(cb) { return client; }; -var semver = require('semver'); -helper.versionGTE = function(client, versionString, callback) { - client.query('SELECT version()', assert.calls(function(err, result) { - if(err) return callback(err); - var version = result.rows[0].version.split(' ')[1]; - return callback(null, semver.gte(version, versionString)); - })); -}; +helper.versionGTE = function (client, testVersion, callback) { + client.query('SHOW server_version_num', assert.calls(function (err, result) { + if (err) return callback(err) + var version = parseInt(result.rows[0].server_version_num, 10) + return callback(null, version >= testVersion) + })) +} //export parent helper stuffs module.exports = helper;