Skip to content

Commit 9e5d77e

Browse files
author
Jessica Lord
committed
fix(url parser): compare string from first period on
1 parent e24574c commit 9e5d77e

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

lib/url_parser.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,12 @@ module.exports = function(url, options, callback) {
7474
}
7575
};
7676

77-
function matchesParentDomain(srvAddress, parentDomain, domains) {
78-
let srv = srvAddress.split('.');
79-
let parent = parentDomain.split('.');
80-
for (let i = 1; i <= domains - 1; i++) {
81-
if (srv[srv.length - i] !== parent[parent.length - i]) {
82-
return false;
83-
}
84-
}
85-
return true;
77+
function matchesParentDomain(srvAddress, parentDomain) {
78+
let regex = /^.*?\./;
79+
let srv = `.${srvAddress.replace(regex, '')}`;
80+
let parent = `.${parentDomain.replace(regex, '')}`;
81+
if (srv.endsWith(parent)) return true;
82+
else return false;
8683
}
8784

8885
function parseHandler(address, options, callback) {

test/functional/url_parser_tests.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1260,13 +1260,11 @@ describe('Url SRV Parser', function() {
12601260
/**
12611261
* @ignore
12621262
*/
1263-
it.only("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
1263+
it("should fail because returned host name's parent (build.10gen.cc) misses 'test'", {
12641264
metadata: {
12651265
requires: { topology: ['single'] }
12661266
},
12671267
test: function(done) {
1268-
// TODO it does return 'test'
1269-
// test.build.10gen.cc
12701268
parse('mongodb+srv://test13.test.build.10gen.cc', function(err) {
12711269
expect(err).to.exist;
12721270
expect(err.message).to.equal('srv record does not share hostname with parent uri');

0 commit comments

Comments
 (0)