Socket
Socket
Sign inDemoInstall

pgpass

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgpass - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

test/#1 de-escaping.js

51

lib/helper.js

@@ -24,3 +24,3 @@ 'use strict';

var nrOfFields = fieldNames.length;
var passKey = fieldNames[ fieldNames.length -1 ];
var passKey = fieldNames[ nrOfFields -1 ];

@@ -117,3 +117,3 @@

pass = entry[passKey];
lineStream.end(); // -> calles onEnd(), but pass is set now
lineStream.end(); // -> calls onEnd(), but pass is set now
}

@@ -146,21 +146,19 @@ }

function addToObj(idx, i0, i1) {
if (idx >= 0 && idx < nrOfFields) {
obj[ fieldNames[idx] ] = line
.substring(i0, i1)
.replace(/\\([:\\])/g, '$1')
;
return true;
} else {
return false;
}
}
var curChar = '';
var prevChar = '';
var curChar = '';
var fieldIdx = 0;
var startIdx = 0;
var endIdx = 0;
var obj = {};
var fieldIdx = 0;
var isOk = false;
var isLastField = false;
var addToObj = function(idx, i0, i1) {
var field = line.substring(i0, i1);
if (! Object.hasOwnProperty.call(process.env, 'PGPASS_NO_DEESCAPE')) {
field = field.replace(/\\([:\\])/g, '$1');
}
obj[ fieldNames[idx] ] = field;
};
for (var i = 0 ; i < line.length-1 ; i += 1) {

@@ -170,6 +168,11 @@ curChar = line.charAt(i+1);

isLastField = (fieldIdx == nrOfFields-1);
if (isLastField) {
addToObj(fieldIdx, startIdx);
break;
}
if (i >= 0 && curChar == ':' && prevChar !== '\\') {
if ( ! addToObj(fieldIdx, startIdx, i+1) ) {
return null;
}
addToObj(fieldIdx, startIdx, i+1);

@@ -180,8 +183,6 @@ startIdx = i+2;

}
isOk = addToObj(fieldIdx, startIdx);
return (
isOk &&
Object.keys(obj).length === nrOfFields
) ? obj : null;
obj = ( Object.keys(obj).length === nrOfFields ) ? obj : null;
return obj;
};

@@ -188,0 +189,0 @@

{
"name": "pgpass",
"version": "0.0.2",
"version": "0.0.3",
"description": "Module for reading .pgpass",

@@ -8,5 +8,5 @@ "main": "lib/index",

"pretest": "chmod 600 ./test/_pgpass",
"test": "npm run hint && mocha -R list && npm run coverage",
"coverage": "rm -rf -- lib-cov ; PATH=$PATH:./node_modules/jscoverage/bin ; jscoverage lib lib-cov && mocha -R html-cov > coverage.html",
"hint": "PATH=$PATH:./node_modules/jshint/bin ; jshint --verbose lib test"
"test": "npm run hint && mocha --recursive -R list && npm run coverage",
"coverage": "rm -rf -- lib-cov ; jscoverage lib lib-cov && mocha --recursive -R html-cov > coverage.html",
"hint": "jshint --verbose lib test"
},

@@ -16,3 +16,3 @@ "author": "Hannes Hörl <hannes.hoerl+pgpass@snowreporter.com>",

"dependencies": {
"split": "~0.2.10"
"split": "~0.3"
},

@@ -23,3 +23,6 @@ "devDependencies": {

"jscoverage": "~0.3.8",
"jshint": "~2.3.0"
"jshint": "~2.3.0",
"pg": "~2.11.1",
"pg-escape": "0.0.2",
"tmp": "0.0.23"
},

@@ -26,0 +29,0 @@ "keywords": [

@@ -8,3 +8,3 @@ # pgpass

```sh
npm install --save hoegaarden/pgpass
npm install pgpass
```

@@ -21,4 +21,2 @@

// ---- async ----
pgPass(connInfo, function(pass){

@@ -32,3 +30,3 @@ conn_info.password = pass;

This module tries to read the `~/.pgpass` file (or the equivalent for windows systems). If the environment variable `PGPASSFILE` is set, this file is used instead. If everything goes right, the password from said file is to the callback; if the password cannot be read `undefined` is passed to the callback.
This module tries to read the `~/.pgpass` file (or the equivalent for windows systems). If the environment variable `PGPASSFILE` is set, this file is used instead. If everything goes right, the password from said file is passed to the callback; if the password cannot be read `undefined` is passed to the callback.

@@ -42,4 +40,9 @@ Cases where `undefined` is returned:

The goal of this package is to get included in the `node-postgresql` module to get the same behaviour for the javascript client as for the native client.
There should be no need to use this module directly; it is already included in `node-postgresq`.
## Configuration
The module reads the environment variable `PGPASS_NO_DEESCAPE` to decide if the the read tokens from the password file should be de-escaped or not. Default is to do de-escaping. For further information on this see [this commit](https://github.com/postgres/postgres/commit/8d15e3ec4fcb735875a8a70a09ec0c62153c3329).
## Tests

@@ -46,0 +49,0 @@

@@ -171,7 +171,8 @@ 'use strict';

it('should ignore too short and too long lines', function(){
it('should ignore too short lines', function(){
var tests = [
'::::' ,
'host:port' ,
'host:port:database:user:pass:some:thing:else'
'host:port:database' ,
'host:port:database:'
];

@@ -178,0 +179,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc