@@ -47,10 +47,44 @@ test('ConnectionParameters initializing from config', function() {
47
47
assert . ok ( subject . isDomainSocket === false ) ;
48
48
} ) ;
49
49
50
+ test ( 'escape spaces if present' , function ( ) {
51
+ subject = new ConnectionParameters ( 'postgres://localhost/post gres' ) ;
52
+ assert . equal ( subject . database , 'post gres' ) ;
53
+ } ) ;
54
+
55
+ test ( 'do not double escape spaces' , function ( ) {
56
+ subject = new ConnectionParameters ( 'postgres://localhost/post%20gres' ) ;
57
+ assert . equal ( subject . database , 'post gres' ) ;
58
+ } ) ;
59
+
50
60
test ( 'initializing with unix domain socket' , function ( ) {
51
61
var subject = new ConnectionParameters ( '/var/run/' ) ;
52
62
assert . ok ( subject . isDomainSocket ) ;
53
63
assert . equal ( subject . host , '/var/run/' ) ;
64
+ assert . equal ( subject . database , defaults . user ) ;
65
+ } ) ;
66
+
67
+ test ( 'initializing with unix domain socket and a specific database, the simple way' , function ( ) {
68
+ var subject = new ConnectionParameters ( '/var/run/ mydb' ) ;
69
+ assert . ok ( subject . isDomainSocket ) ;
70
+ assert . equal ( subject . host , '/var/run/' ) ;
71
+ assert . equal ( subject . database , 'mydb' ) ;
72
+ } ) ;
73
+
74
+ test ( 'initializing with unix domain socket, the health way' , function ( ) {
75
+ var subject = new ConnectionParameters ( 'socket:/some path/?db=my[db]&encoding=utf8' ) ;
76
+ assert . ok ( subject . isDomainSocket ) ;
77
+ assert . equal ( subject . host , '/some path/' ) ;
78
+ assert . equal ( subject . database , 'my[db]' , 'must to be escaped and unescaped trough "my%5Bdb%5D"' ) ;
79
+ assert . equal ( subject . client_encoding , 'utf8' ) ;
80
+ } ) ;
81
+
82
+ test ( 'initializing with unix domain socket, the escaped health way' , function ( ) {
83
+ var subject = new ConnectionParameters ( 'socket:/some%20path/?db=my%2Bdb&encoding=utf8' ) ;
84
+ assert . ok ( subject . isDomainSocket ) ;
85
+ assert . equal ( subject . host , '/some path/' ) ;
86
+ assert . equal ( subject . database , 'my+db' ) ;
87
+ assert . equal ( subject . client_encoding , 'utf8' ) ;
54
88
} ) ;
55
89
56
90
test ( 'libpq connection string building' , function ( ) {
0 commit comments