Skip to content

Commit

Permalink
fix: don't add empty query string items to connection string
Browse files Browse the repository at this point in the history
In the legacy parser, if no query string items are parsed from a
TXT record look up, no items should be added to the second parse
  • Loading branch information
mbroadst committed Nov 23, 2020
1 parent 73ded39 commit 8897259
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/url_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,16 @@ module.exports = function(url, options, callback) {

record = record[0].join('');
const parsedRecord = qs.parse(record);
if (Object.keys(parsedRecord).some(key => key !== 'authSource' && key !== 'replicaSet')) {
const items = Object.keys(parsedRecord);
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
Expand Down

0 comments on commit 8897259

Please sign in to comment.