Skip to content

Commit

Permalink
fix(url parser): compare string from first period on
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lord committed Nov 20, 2017
1 parent e24574c commit 9e5d77e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 6 additions & 9 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,12 @@ module.exports = function(url, options, callback) {
}
};

function matchesParentDomain(srvAddress, parentDomain, domains) {
let srv = srvAddress.split('.');
let parent = parentDomain.split('.');
for (let i = 1; i <= domains - 1; i++) {
if (srv[srv.length - i] !== parent[parent.length - i]) {
return false;
}
}
return true;
function matchesParentDomain(srvAddress, parentDomain) {
let regex = /^.*?\./;
let srv = `.${srvAddress.replace(regex, '')}`;
let parent = `.${parentDomain.replace(regex, '')}`;
if (srv.endsWith(parent)) return true;
else return false;
}

function parseHandler(address, options, callback) {
Expand Down
4 changes: 1 addition & 3 deletions test/functional/url_parser_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,13 +1260,11 @@ describe('Url SRV Parser', function() {
/**
* @ignore
*/
it.only("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
it("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
metadata: {
requires: { topology: ['single'] }
},
test: function(done) {
// TODO it does return 'test'
// test.build.10gen.cc
parse('mongodb+srv://test13.test.build.10gen.cc', function(err) {
expect(err).to.exist;
expect(err.message).to.equal('srv record does not share hostname with parent uri');
Expand Down

0 comments on commit 9e5d77e

Please sign in to comment.