Permalink
Browse files

Incorrectly parsing pgpass file

The package doesn't appear to correctly parse pgpass files with colons in the password.

#1

closes: #1
  • Loading branch information...
1 parent 155216b commit d40bde90fd305c8e7a067faba130ed7f1575e163 @hoegaarden committed Mar 9, 2014
Showing with 35 additions and 1 deletion.
  1. +1 −1 lib/helper.js
  2. +31 −0 test/#1 escaping.js
  3. +3 −0 test/_pgpass
View
@@ -145,7 +145,7 @@ var parseLine = module.exports.parseLine = function(line) {
if (idx >= 0 && idx < nrOfFields) {
obj[ fieldNames[idx] ] = line
.substring(i0, i1)
- .replace(/\\([:\\])/, '$1')
+ .replace(/\\([:\\])/g, '$1')
;
return true;
} else {
View
@@ -0,0 +1,31 @@
+'use strict';
+
+/* global describe: false */
+/* global it: false */
+
+/* jshint -W106 */
+var COV = process.env.npm_lifecycle_event === 'coverage';
+/* jshint +W106 */
+
+var assert = require('assert')
+ , path = require('path')
+ , pgPass = require( path.join('..', COV ? 'lib-cov' : 'lib' , 'index') )
+;
+
+
+var conn = {
+ 'host' : 'host4' ,
+ 'port' : 100 ,
+ 'database' : 'database4' ,
+ 'user' : 'user4'
+};
+
+describe('#1', function(){
+ it('should handle escaping right', function(done){
+ process.env.PGPASSFILE = path.join(__dirname, '_pgpass');
+ pgPass(conn, function(res){
+ assert.strictEqual('some:wired:password', res);
+ done();
+ });
+ });
+});
View
@@ -3,3 +3,6 @@ host1:1:database1:user1:pass1
*:*:*:user2:pass2
host3:3:database3:user3:pass3
+host4:*:database4:user4:some\:wired\:password
+
+

0 comments on commit d40bde9

Please sign in to comment.