Skip to content

Commit f658b31

Browse files
committed
Changing to client_encoding, adding test for creating a connection
1 parent d690705 commit f658b31

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/connection-parameters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var ConnectionParameters = function(config) {
3838
this.password = val('password', config);
3939
this.binary = val('binary', config);
4040
this.ssl = config.ssl || defaults.ssl;
41-
this.client_encoding = config.encoding || defaults.encoding;
41+
this.client_encoding = config.client_encoding || defaults.client_encoding;
4242
//a domain socket begins with '/'
4343
this.isDomainSocket = (!(this.host||'').indexOf('/'));
4444
};
@@ -63,7 +63,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) {
6363
return cb(null, params.join(' '));
6464
}
6565
if(this.client_encoding) {
66-
params.push(this.client_encoding);
66+
params.push("client_encoding='" + this.client_encoding + "'");
6767
}
6868
dns.lookup(this.host, function(err, address) {
6969
if(err) return cb(err, null);

test/unit/connection-parameters/creation-tests.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ test('libpq connection string building', function() {
124124
}));
125125
});
126126

127+
test("encoding can be specified by config", function() {
128+
var config = {
129+
client_encoding: "utf-8"
130+
}
131+
var subject = new ConnectionParameters(config);
132+
subject.getLibpqConnectionString(assert.calls(function(err, constring) {
133+
assert.isNull(err);
134+
var parts = constring.split(" ");
135+
checkForPart(parts, "client_encoding='utf-8'");
136+
}));
137+
})
138+
127139
test('password contains < and/or > characters', function () {
128140
return false;
129141
var sourceConfig = {

0 commit comments

Comments
 (0)