Skip to content

Commit d40bde9

Browse files
committed
Incorrectly parsing pgpass file
The package doesn't appear to correctly parse pgpass files with colons in the password. #1 closes: #1
1 parent 155216b commit d40bde9

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

lib/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var parseLine = module.exports.parseLine = function(line) {
145145
if (idx >= 0 && idx < nrOfFields) {
146146
obj[ fieldNames[idx] ] = line
147147
.substring(i0, i1)
148-
.replace(/\\([:\\])/, '$1')
148+
.replace(/\\([:\\])/g, '$1')
149149
;
150150
return true;
151151
} else {

test/#1 escaping.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
/* global describe: false */
4+
/* global it: false */
5+
6+
/* jshint -W106 */
7+
var COV = process.env.npm_lifecycle_event === 'coverage';
8+
/* jshint +W106 */
9+
10+
var assert = require('assert')
11+
, path = require('path')
12+
, pgPass = require( path.join('..', COV ? 'lib-cov' : 'lib' , 'index') )
13+
;
14+
15+
16+
var conn = {
17+
'host' : 'host4' ,
18+
'port' : 100 ,
19+
'database' : 'database4' ,
20+
'user' : 'user4'
21+
};
22+
23+
describe('#1', function(){
24+
it('should handle escaping right', function(done){
25+
process.env.PGPASSFILE = path.join(__dirname, '_pgpass');
26+
pgPass(conn, function(res){
27+
assert.strictEqual('some:wired:password', res);
28+
done();
29+
});
30+
});
31+
});

test/_pgpass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ host1:1:database1:user1:pass1
33
*:*:*:user2:pass2
44
host3:3:database3:user3:pass3
55

6+
host4:*:database4:user4:some\:wired\:password
7+
8+

0 commit comments

Comments
 (0)