pg-connection-string
Advanced tools
Comparing version 0.1.1 to 0.1.2
10
index.js
@@ -39,3 +39,11 @@ 'use strict'; | ||
config.host = result.hostname; | ||
config.database = result.pathname ? decodeURI(result.pathname.slice(1)) : null; | ||
// result.pathname is not always guaranteed to have a '/' prefix (e.g. relative urls) | ||
// only strip the slash if it is present. | ||
var pathname = result.pathname; | ||
if (pathname && pathname.charAt(0) === '/') { | ||
pathname = result.pathname.slice(1) || null; | ||
} | ||
config.database = pathname && decodeURI(pathname); | ||
var auth = (result.auth || ':').split(':'); | ||
@@ -42,0 +50,0 @@ config.user = auth[0]; |
{ | ||
"name": "pg-connection-string", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Functions for dealing with a PostgresSQL connection string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -90,1 +90,24 @@ 'use strict'; | ||
}); | ||
test('relative url sets database', function(t){ | ||
var relative = 'different_db_on_default_host'; | ||
var subject = parse(relative); | ||
t.equal(subject.database, 'different_db_on_default_host'); | ||
t.end(); | ||
}); | ||
test('no pathname returns null database', function (t) { | ||
var subject = parse('pg://myhost'); | ||
t.equal(subject.host, 'myhost'); | ||
t.type(subject.database, 'null'); | ||
t.end(); | ||
}); | ||
test('pathname of "/" returns null database', function (t) { | ||
var subject = parse('pg://myhost/'); | ||
t.equal(subject.host, 'myhost'); | ||
t.type(subject.database, 'null'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8004
147