From d69070529c9dc1820c017508cc34d3ae612c986a Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 6 Jun 2013 12:06:52 -0700 Subject: [PATCH 1/4] Makes encoding an optional parameter --- lib/connection-parameters.js | 5 ++++- lib/defaults.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 91ad663c..fa46e5da 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -38,6 +38,7 @@ var ConnectionParameters = function(config) { this.password = val('password', config); this.binary = val('binary', config); this.ssl = config.ssl || defaults.ssl; + this.client_encoding = config.encoding || defaults.encoding; //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); }; @@ -61,7 +62,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { params.push("host=" + this.host); return cb(null, params.join(' ')); } - params.push("client_encoding='utf-8'"); + if(this.client_encoding) { + params.push(this.client_encoding); + } dns.lookup(this.host, function(err, address) { if(err) return cb(err, null); params.push("hostaddr=" + address); diff --git a/lib/defaults.js b/lib/defaults.js index 738908ee..2b219200 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -31,5 +31,7 @@ module.exports = { reapIntervalMillis: 1000, //pool log function / boolean - poolLog: false + poolLog: false, + + encoding: "" }; From f658b31aed3b1c7f18c84d85f06e505075446ff3 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 6 Jun 2013 12:16:36 -0700 Subject: [PATCH 2/4] Changing to client_encoding, adding test for creating a connection --- lib/connection-parameters.js | 4 ++-- test/unit/connection-parameters/creation-tests.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index fa46e5da..84fa5fdc 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -38,7 +38,7 @@ var ConnectionParameters = function(config) { this.password = val('password', config); this.binary = val('binary', config); this.ssl = config.ssl || defaults.ssl; - this.client_encoding = config.encoding || defaults.encoding; + this.client_encoding = config.client_encoding || defaults.client_encoding; //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); }; @@ -63,7 +63,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { return cb(null, params.join(' ')); } if(this.client_encoding) { - params.push(this.client_encoding); + params.push("client_encoding='" + this.client_encoding + "'"); } dns.lookup(this.host, function(err, address) { if(err) return cb(err, null); diff --git a/test/unit/connection-parameters/creation-tests.js b/test/unit/connection-parameters/creation-tests.js index 6e73f7cd..90ec18a5 100644 --- a/test/unit/connection-parameters/creation-tests.js +++ b/test/unit/connection-parameters/creation-tests.js @@ -124,6 +124,18 @@ test('libpq connection string building', function() { })); }); + test("encoding can be specified by config", function() { + var config = { + client_encoding: "utf-8" + } + var subject = new ConnectionParameters(config); + subject.getLibpqConnectionString(assert.calls(function(err, constring) { + assert.isNull(err); + var parts = constring.split(" "); + checkForPart(parts, "client_encoding='utf-8'"); + })); + }) + test('password contains < and/or > characters', function () { return false; var sourceConfig = { From 6b4bc3945f4051b3d758087a9e940d39d7ff7826 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 6 Jun 2013 12:24:12 -0700 Subject: [PATCH 3/4] Uses val function instead --- lib/connection-parameters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 84fa5fdc..9f44c8e9 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -38,7 +38,7 @@ var ConnectionParameters = function(config) { this.password = val('password', config); this.binary = val('binary', config); this.ssl = config.ssl || defaults.ssl; - this.client_encoding = config.client_encoding || defaults.client_encoding; + this.client_encoding = val("client_encoding", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); }; From 6fea79712c5de9032a3e2d7346516326e7d7c8ce Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 6 Jun 2013 12:32:04 -0700 Subject: [PATCH 4/4] Client encoding in defaults as well --- lib/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/defaults.js b/lib/defaults.js index 2b219200..d15a5b7b 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -33,5 +33,5 @@ module.exports = { //pool log function / boolean poolLog: false, - encoding: "" + client_encoding: "" };