Skip to content

Commit ab73b78

Browse files
committed
Specify behavior where connection string contain auth
database but no credentials JAVA-3298
1 parent cf09825 commit ab73b78

File tree

3 files changed

+203
-250
lines changed

3 files changed

+203
-250
lines changed

driver-core/src/main/com/mongodb/ConnectionString.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,14 @@ public ConnectionString(final String connectionString) {
324324
userName = urldecode(userInfo);
325325
} else {
326326
idx = userInfo.indexOf(":");
327+
if (idx == 0) {
328+
throw new IllegalArgumentException("No username is provided in the connection string");
329+
}
327330
userName = urldecode(userInfo.substring(0, idx));
328331
password = urldecode(userInfo.substring(idx + 1), true).toCharArray();
329332
}
333+
} else if (idx == 0) {
334+
throw new IllegalArgumentException("The connection string contains an at-sign (@) without a user name");
330335
} else {
331336
hostIdentifier = userAndHostInformation;
332337
}

0 commit comments

Comments
 (0)