Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
fix(uri-parser): Incorrect parsing of arrays
Browse files Browse the repository at this point in the history
Arrays passed in to the uri string by repeating fields
are now parsed correctly.

Fixes NODE-1605
  • Loading branch information
rweinberger authored Aug 2, 2018
1 parent c93aac1 commit fcff104
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/uri_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function parseSrvConnectionString(uri, options, callback) {
function parseQueryStringItemValue(value) {
if (Array.isArray(value)) {
// deduplicate and simplify arrays
value = value.filter((value, idx) => value.indexOf(value) === idx);
value = value.filter((v, idx) => value.indexOf(v) === idx);
if (value.length === 1) value = value[0];
} else if (value.indexOf(':') > 0) {
value = value.split(',').reduce((result, pair) => {
Expand Down
8 changes: 8 additions & 0 deletions test/tests/unit/connection_string_spec_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('Connection String (spec)', function() {
});
});

it('should correctly parse arrays', function(done) {
parseConnectionString('mongodb://hostname?foo=bar&foo=baz', function(err, result) {
expect(err).to.not.exist;
expect(result.options.foo).to.deep.equal(['bar', 'baz']);
done();
});
});

const testFiles = fs
.readdirSync(f('%s/../spec/connection-string', __dirname))
.filter(x => x.indexOf('.json') !== -1)
Expand Down

0 comments on commit fcff104

Please sign in to comment.