Skip to content

Commit e876a72

Browse files
committed
fix(url parser): keep original uri options and default to ssl true
1 parent d9f4218 commit e876a72

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/url_parser.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ module.exports = function(url, options, callback) {
1717
}
1818

1919
if (result.protocol === 'mongodb+srv:') {
20-
if (options) {
21-
// TODO let the options passed in override
22-
if (options.ssl && options.ssl !== true) {
23-
options.ssl = true;
24-
}
25-
}
20+
2621
if (result.hostname.split('.').length < 3) {
2722
return callback(new Error('uri does not have hostname, domainname and tld'));
2823
}
@@ -56,15 +51,28 @@ module.exports = function(url, options, callback) {
5651
else return `${address.name}:${address.port}`;
5752
});
5853

59-
let connectionString = connectionStrings.join(',') + '/?';
54+
let connectionString = connectionStrings.join(',') + '/';
55+
56+
if (!options.ssl && !result.search.match('ssl')) {
57+
// Default to SSL true
58+
connectionString += '?ssl=true';
59+
} else if (!result.search) connectionString += '?'
60+
// Keep original uri options
61+
if (result.search && !result.search.match('ssl')) {
62+
connectionString += result.search.replace('?', '&');
63+
} else if (result.search && result.search.match('ssl')) {
64+
connectionString += result.search;
65+
}
6066

6167
dns.resolveTxt(result.host, function(err, record) {
6268
if (err && err.code !== 'ENODATA') return callback(err);
6369
if (err && err.code === 'ENODATA') record = null;
70+
6471
if (record) {
6572
if (record.length > 1) {
6673
return callback(new Error('multiple text records not allowed'));
6774
}
75+
6876
record = record[0];
6977
if (record.length > 1) record = record.join('');
7078
else record = record[0];
@@ -73,9 +81,8 @@ module.exports = function(url, options, callback) {
7381
return callback(new Error('text record must only set `authSource` or `replicaSet`'));
7482
}
7583

76-
connectionString += record;
84+
connectionString += '&' + record;
7785
}
78-
7986
parseHandler(connectionString, options, callback);
8087
});
8188
});

0 commit comments

Comments
 (0)