From 9e5d77e06500269266545998c17e0324f8ea6fce Mon Sep 17 00:00:00 2001 From: Jessica Lord Date: Mon, 20 Nov 2017 17:09:34 -0500 Subject: [PATCH] fix(url parser): compare string from first period on --- lib/url_parser.js | 15 ++++++--------- test/functional/url_parser_tests.js | 4 +--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/url_parser.js b/lib/url_parser.js index 2bb89361d9..829303717b 100644 --- a/lib/url_parser.js +++ b/lib/url_parser.js @@ -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) { diff --git a/test/functional/url_parser_tests.js b/test/functional/url_parser_tests.js index f9a13e550b..e6bfcc76cb 100644 --- a/test/functional/url_parser_tests.js +++ b/test/functional/url_parser_tests.js @@ -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');