Skip to content

Commit aa9871b

Browse files
jlordJessica Lord
authored and
Jessica Lord
committed
fix(url parser): make sure uri has 3 parts
1 parent fc09ca9 commit aa9871b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/url_parser.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module.exports = function(url, options, callback) {
1717
}
1818

1919
if (result.protocol === 'mongodb+srv:') {
20+
if (result.hostname.split('.').length < 3) {
21+
return callback(new Error('uri does not have hostname, domainname and tld'))
22+
}
2023
if (result.pathname && result.pathname.match(',')) {
2124
return callback(new Error('invalid uri, cannot contain multiple hostnames'));
2225
}

test/functional/url_parser_tests.js

+16
Original file line numberDiff line numberDiff line change
@@ -1240,4 +1240,20 @@ describe('Url SRV Parser', function() {
12401240
});
12411241
}
12421242
});
1243+
1244+
/**
1245+
* @ignore
1246+
*/
1247+
it('should fail because host in URI does not have hostname, domainname and tld', {
1248+
metadata: {
1249+
requires: { topology: ['single'] }
1250+
},
1251+
test: function(done) {
1252+
parse('mongodb+srv://10gen.cc', function(err, object) {
1253+
expect(err).to.exist;
1254+
expect(err.message).to.equal('uri does not have hostname, domainname and tld');
1255+
done();
1256+
});
1257+
}
1258+
});
12431259
});

0 commit comments

Comments
 (0)