From d00b1ab7d2df082e8cbd8e14e430c0d25ca25cdc Mon Sep 17 00:00:00 2001 From: Kev Date: Mon, 29 Oct 2018 09:02:57 -0400 Subject: [PATCH] fix(uri_parser): add `replSet` to exemption list for number coercion * fix(uri_parser) bypass number coercion for replicaSet values in connection string * fix (uri_parser) do not coerce replicaSet with leading number to number --- lib/uri_parser.js | 2 +- test/tests/unit/connection_string_tests.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/uri_parser.js b/lib/uri_parser.js index 507e40ebc..8ff66b142 100644 --- a/lib/uri_parser.js +++ b/lib/uri_parser.js @@ -175,7 +175,7 @@ const BOOLEAN_OPTIONS = new Set([ ]); // Known string options, only used to bypass Number coercion in `parseQueryStringItemValue` -const STRING_OPTIONS = new Set(['authsource']); +const STRING_OPTIONS = new Set(['authsource', 'replicaset']); // Supported text representations of auth mechanisms // NOTE: this list exists in native already, if it is merged here we should deduplicate diff --git a/test/tests/unit/connection_string_tests.js b/test/tests/unit/connection_string_tests.js index 5c6b69d37..30cfb75be 100644 --- a/test/tests/unit/connection_string_tests.js +++ b/test/tests/unit/connection_string_tests.js @@ -119,6 +119,16 @@ describe('Connection String', function() { }); }); + it('should parse a replicaSet with a leading number', function(done) { + parseConnectionString('mongodb://localhost/?replicaSet=123abc', (err, result) => { + expect(err).to.not.exist; + expect(result.options).to.have.property('replicaSet'); + expect(result.options.replicaSet).to.equal('123abc'); + + done(); + }); + }); + describe('validation', function() { it('should validate compression options', function(done) { parseConnectionString('mongodb://localhost/?zlibCompressionLevel=15', err => {