Cleanup
This commit is contained in:
44
node_modules/mongodb/lib/url_parser.js
generated
vendored
44
node_modules/mongodb/lib/url_parser.js
generated
vendored
@@ -1,11 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const ReadPreference = require('./core').ReadPreference,
|
||||
parser = require('url'),
|
||||
f = require('util').format,
|
||||
Logger = require('./core').Logger,
|
||||
dns = require('dns');
|
||||
const ReadPreference = require('./core').ReadPreference;
|
||||
const parser = require('url');
|
||||
const f = require('util').format;
|
||||
const Logger = require('./core').Logger;
|
||||
const dns = require('dns');
|
||||
const ReadConcern = require('./read_concern');
|
||||
const qs = require('querystring');
|
||||
const MongoParseError = require('./core/error').MongoParseError;
|
||||
|
||||
module.exports = function(url, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
@@ -33,7 +35,8 @@ module.exports = function(url, options, callback) {
|
||||
|
||||
result.domainLength = result.hostname.split('.').length;
|
||||
|
||||
if (result.pathname && result.pathname.match(',')) {
|
||||
const hostname = url.substring('mongodb+srv://'.length).split('/')[0];
|
||||
if (hostname.match(',')) {
|
||||
return callback(new Error('Invalid URI, cannot contain multiple hostnames'));
|
||||
}
|
||||
|
||||
@@ -87,23 +90,29 @@ module.exports = function(url, options, callback) {
|
||||
}
|
||||
|
||||
dns.resolveTxt(result.host, function(err, record) {
|
||||
if (err && err.code !== 'ENODATA') return callback(err);
|
||||
if (err && err.code !== 'ENODATA' && err.code !== 'ENOTFOUND') return callback(err);
|
||||
if (err && err.code === 'ENODATA') record = null;
|
||||
|
||||
if (record) {
|
||||
if (record.length > 1) {
|
||||
return callback(new Error('Multiple text records not allowed'));
|
||||
return callback(new MongoParseError('Multiple text records not allowed'));
|
||||
}
|
||||
|
||||
record = record[0];
|
||||
if (record.length > 1) record = record.join('');
|
||||
else record = record[0];
|
||||
|
||||
if (!record.includes('authSource') && !record.includes('replicaSet')) {
|
||||
return callback(new Error('Text record must only set `authSource` or `replicaSet`'));
|
||||
record = record[0].join('');
|
||||
const parsedRecord = qs.parse(record);
|
||||
const items = Object.keys(parsedRecord);
|
||||
if (Object.keys(items).some(k => k.toLowerCase() === 'loadbalanced')) {
|
||||
return callback(new MongoParseError('Load balancer mode requires driver version 4+'));
|
||||
}
|
||||
if (items.some(item => item !== 'authSource' && item !== 'replicaSet')) {
|
||||
return callback(
|
||||
new MongoParseError('Text record must only set `authSource` or `replicaSet`')
|
||||
);
|
||||
}
|
||||
|
||||
connectionStringOptions.push(record);
|
||||
if (items.length > 0) {
|
||||
connectionStringOptions.push(record);
|
||||
}
|
||||
}
|
||||
|
||||
// Add any options to the connection string
|
||||
@@ -372,6 +381,11 @@ function parseConnectionString(url, options) {
|
||||
object.dbName = dbName || 'admin';
|
||||
// Split up all the options
|
||||
urlOptions = (query_string_part || '').split(/[&;]/);
|
||||
|
||||
if (urlOptions.some(k => k.toLowerCase() === 'loadbalanced')) {
|
||||
throw new MongoParseError('Load balancer mode requires driver version 4+');
|
||||
}
|
||||
|
||||
// Ugh, we have to figure out which options go to which constructor manually.
|
||||
urlOptions.forEach(function(opt) {
|
||||
if (!opt) return;
|
||||
|
||||
Reference in New Issue
Block a user