iceddev/pg-connection-string — pull request #1 by slickmb (2014-09-12 15:58:05+00:00)
Title: Support usage of relative urls to set database on the default host

Ran into a real-world use-case in node-postgres where the host name was being set using an environment variable, but we needed to change the database in code. node-postgres was being wrapped in other code that we could not edit for beurocratic reasons. This code prevented us from passing config objects (i.e. forced us to pass a connection 'string'). The current code assumes that the pathname returned by nodejs will always have a leading '/'. This is true for fully qualified urls, but NOT true for relative urls. This caused pg-connection-string to return a database config object where the database was missing it's first character. There are work-arounds, but it seems like something that is easily supported.

```JavaScript
var pg = require('pg');

console.log(process.env.PGHOST); // '/tmp'
console.log(process.env.PGDATABASE); // 'default_db'

// this fails, as it tries to connect to 'yotherdb' after striping the first character.
pg.connect('my_other_db', function (err, client, done) {
});

//a hacky workaround. Works because it strips the '.' and leaves the rest of the db.
pg.connect('.my_other_db', function (err, client, done) {
});
```