diff --git a/lib/url_parser.js b/lib/url_parser.js index 641e6585f3..6c1ca88099 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -17,6 +17,9 @@ module.exports = function(url, options, callback) { } if (result.protocol === 'mongodb+srv:') { + if (result.hostname.split('.').length < 3) { + return callback(new Error('uri does not have hostname, domainname and tld')) + } if (result.pathname && result.pathname.match(',')) { return callback(new Error('invalid uri, cannot contain multiple hostnames')); } diff --git a/test/functional/url_parser_tests.js b/test/functional/url_parser_tests.js index c60bf8d08b..386b82072a 100644 --- a/test/functional/url_parser_tests.js +++ b/test/functional/url_parser_tests.js @@ -1240,4 +1240,20 @@ describe('Url SRV Parser', function() { }); } }); + + /** + * @ignore + */ + it('should fail because host in URI does not have hostname, domainname and tld', { + metadata: { + requires: { topology: ['single'] } + }, + test: function(done) { + parse('mongodb+srv://10gen.cc', function(err, object) { + expect(err).to.exist; + expect(err.message).to.equal('uri does not have hostname, domainname and tld'); + done(); + }); + } + }); });