|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const ReadPreference = require('./core').ReadPreference, |
4 | | - parser = require('url'), |
5 | | - f = require('util').format, |
6 | | - Logger = require('./core').Logger, |
7 | | - dns = require('dns'); |
| 3 | +const ReadPreference = require('./core').ReadPreference; |
| 4 | +const parser = require('url'); |
| 5 | +const f = require('util').format; |
| 6 | +const Logger = require('./core').Logger; |
| 7 | +const dns = require('dns'); |
8 | 8 | const ReadConcern = require('./read_concern'); |
| 9 | +const qs = require('querystring'); |
| 10 | +const MongoParseError = require('./core/error').MongoParseError; |
9 | 11 |
|
10 | 12 | module.exports = function(url, options, callback) { |
11 | 13 | if (typeof options === 'function') (callback = options), (options = {}); |
@@ -87,20 +89,20 @@ module.exports = function(url, options, callback) { |
87 | 89 | } |
88 | 90 |
|
89 | 91 | dns.resolveTxt(result.host, function(err, record) { |
90 | | - if (err && err.code !== 'ENODATA') return callback(err); |
| 92 | + if (err && err.code !== 'ENODATA' && err.code !== 'ENOTFOUND') return callback(err); |
91 | 93 | if (err && err.code === 'ENODATA') record = null; |
92 | 94 |
|
93 | 95 | if (record) { |
94 | 96 | if (record.length > 1) { |
95 | | - return callback(new Error('Multiple text records not allowed')); |
| 97 | + return callback(new MongoParseError('Multiple text records not allowed')); |
96 | 98 | } |
97 | 99 |
|
98 | | - record = record[0]; |
99 | | - if (record.length > 1) record = record.join(''); |
100 | | - else record = record[0]; |
101 | | - |
102 | | - if (!record.includes('authSource') && !record.includes('replicaSet')) { |
103 | | - return callback(new Error('Text record must only set `authSource` or `replicaSet`')); |
| 100 | + record = record[0].join(''); |
| 101 | + const parsedRecord = qs.parse(record); |
| 102 | + if (Object.keys(parsedRecord).some(key => key !== 'authSource' && key !== 'replicaSet')) { |
| 103 | + return callback( |
| 104 | + new MongoParseError('Text record must only set `authSource` or `replicaSet`') |
| 105 | + ); |
104 | 106 | } |
105 | 107 |
|
106 | 108 | connectionStringOptions.push(record); |
|
0 commit comments