File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -211,13 +211,14 @@ module.exports = {
211
211
//
212
212
// Remember: connection string takes priority over `meta` in the event of a conflict.
213
213
try {
214
- var parsedConnectionStr = Url . parse ( inputs . connectionString ) ;
215
-
216
- // Validate that a protocol was found before other pieces
217
- // (otherwise other parsed info will be very weird and wrong)
218
- if ( ! parsedConnectionStr . protocol || parsedConnectionStr . protocol !== 'mysql:' ) {
219
- throw new Error ( 'Protocol (i.e. ` mysql://`) is required in connection string.' ) ;
214
+ var urlToParse = inputs . connectionString ;
215
+ // We don't actually care about the protocol, but `url.parse()` returns funky results
216
+ // if the argument doesn't have one. So we'll add one if necessary.
217
+ // See https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax
218
+ if ( ! urlToParse . match ( / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 + . - ] * : \/ \/ / ) ) {
219
+ urlToParse = ' mysql://' + urlToParse ;
220
220
}
221
+ var parsedConnectionStr = Url . parse ( urlToParse ) ;
221
222
222
223
// Parse port & host
223
224
var DEFAULT_HOST = 'localhost' ;
Original file line number Diff line number Diff line change @@ -3,14 +3,14 @@ var Pack = require('../../');
3
3
4
4
describe ( 'Connectable ::' , function ( ) {
5
5
describe ( 'Create Manager' , function ( ) {
6
- it ( 'should validate the connection string has a protocol ' , function ( done ) {
6
+ it ( 'should work without a protocol in the connection string ' , function ( done ) {
7
7
Pack . createManager ( {
8
8
connectionString : 'localhost:5432/mppg'
9
9
} )
10
10
. exec ( function ( err ) {
11
- assert ( err ) ;
12
- assert . equal ( err . exit , 'malformed' ) ;
13
-
11
+ if ( err ) {
12
+ return done ( err ) ;
13
+ }
14
14
return done ( ) ;
15
15
} ) ;
16
16
} ) ;
You can’t perform that action at this time.
0 commit comments