Skip to content

Commit dbe05b8

Browse files
Merge pull request sailshq#5 from treelinehq/allow-url-without-protocol
Allow any protocol, or no protocol at all.
2 parents 17c6b1d + 3f1c65d commit dbe05b8

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

machines/create-manager.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ module.exports = {
211211
//
212212
// Remember: connection string takes priority over `meta` in the event of a conflict.
213213
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-zA-Z][a-zA-Z0-9+.-]*:\/\//)) {
219+
urlToParse = 'mysql://' + urlToParse;
220220
}
221+
var parsedConnectionStr = Url.parse(urlToParse);
221222

222223
// Parse port & host
223224
var DEFAULT_HOST = 'localhost';

test/connectable/create-manager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ var Pack = require('../../');
33

44
describe('Connectable ::', function() {
55
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) {
77
Pack.createManager({
88
connectionString: 'localhost:5432/mppg'
99
})
1010
.exec(function(err) {
11-
assert(err);
12-
assert.equal(err.exit, 'malformed');
13-
11+
if (err) {
12+
return done(err);
13+
}
1414
return done();
1515
});
1616
});

0 commit comments

Comments
 (0)