Skip to content

Commit

Permalink
fix(url parser): make sure uri has 3 parts
Browse files Browse the repository at this point in the history
  • Loading branch information
jlord authored and Jessica Lord committed Nov 20, 2017
1 parent fc09ca9 commit aa9871b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
16 changes: 16 additions & 0 deletions test/functional/url_parser_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});
});

0 comments on commit aa9871b

Please sign in to comment.