Skip to content

Commit 8897259

Browse files
committed
fix: don't add empty query string items to connection string
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
1 parent 73ded39 commit 8897259

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/url_parser.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@ module.exports = function(url, options, callback) {
9999

100100
record = record[0].join('');
101101
const parsedRecord = qs.parse(record);
102-
if (Object.keys(parsedRecord).some(key => key !== 'authSource' && key !== 'replicaSet')) {
102+
const items = Object.keys(parsedRecord);
103+
if (items.some(item => item !== 'authSource' && item !== 'replicaSet')) {
103104
return callback(
104105
new MongoParseError('Text record must only set `authSource` or `replicaSet`')
105106
);
106107
}
107108

108-
connectionStringOptions.push(record);
109+
if (items.length > 0) {
110+
connectionStringOptions.push(record);
111+
}
109112
}
110113

111114
// Add any options to the connection string

0 commit comments

Comments
 (0)