From 5a31cdabe5d87f461d22bcffe346723b46802d92 Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Fri, 10 Feb 2023 15:53:58 -0500 Subject: [PATCH] Test comma in db name JAVA-4196 --- .../dbname-with-commas-escaped.json | 19 +++++++++++++++++++ .../replica-set/dbname-with-commas.json | 19 +++++++++++++++++++ .../ConnectionStringSpecification.groovy | 2 ++ .../InitialDnsSeedlistDiscoveryTest.java | 1 + 4 files changed, 41 insertions(+) create mode 100644 driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas-escaped.json create mode 100644 driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas.json diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas-escaped.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas-escaped.json new file mode 100644 index 00000000000..b5fcfd2c07b --- /dev/null +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas-escaped.json @@ -0,0 +1,19 @@ +{ + "uri": "mongodb+srv://test1.test.build.10gen.cc/some%2Cdb?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017", + "localhost.test.build.10gen.cc:27018" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "defaultDatabase": "some,db" + } +} diff --git a/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas.json b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas.json new file mode 100644 index 00000000000..c1e85f4b99f --- /dev/null +++ b/driver-core/src/test/resources/initial-dns-seedlist-discovery/replica-set/dbname-with-commas.json @@ -0,0 +1,19 @@ +{ + "uri": "mongodb+srv://test1.test.build.10gen.cc/some,db?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017", + "localhost.test.build.10gen.cc:27018" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "defaultDatabase": "some,db" + } +} diff --git a/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy b/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy index 03ba4303fd3..be9702b6588 100644 --- a/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy +++ b/driver-core/src/test/unit/com/mongodb/ConnectionStringSpecification.groovy @@ -64,6 +64,8 @@ class ConnectionStringSpecification extends Specification { new ConnectionString('mongodb://localhost/' + 'test.my.coll') | 1 | ['localhost'] | 'test' | 'my.coll' | null | null new ConnectionString('mongodb://foo/bar.goo') | 1 | ['foo'] | 'bar' | 'goo' | null | null + new ConnectionString('mongodb://foo/s,db') | 1 | ['foo'] | 's,db'| null | null | null + new ConnectionString('mongodb://foo/s%2Cdb') | 1 | ['foo'] | 's,db'| null | null | null new ConnectionString('mongodb://user:pass@' + 'host/bar') | 1 | ['host'] | 'bar' | null | 'user' | 'pass' as char[] new ConnectionString('mongodb://user:pass@' + diff --git a/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java b/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java index 983e6370a69..a51f6e3624d 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/InitialDnsSeedlistDiscoveryTest.java @@ -281,6 +281,7 @@ private void assertParsedOptions(final ConnectionString connectionString) { for (Map.Entry entry : parsedOptions.entrySet()) { switch (entry.getKey()) { case "db": + case "defaultDatabase": assertEquals(entry.getValue().asString().getValue(), connectionString.getDatabase()); break; case "user":