Skip to content

Commit ff16913

Browse files
Merge pull request #19 from mongodb-js/COMPASS-5471-check-missing-host-after-auth
fix: check missing host after auth COMPASS-5471
2 parents 93b8b28 + 8d71668 commit ff16913

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function connectionStringHasValidScheme(connectionString: string) {
1818
// Adapted from the Node.js driver code:
1919
// https://github.com/mongodb/node-mongodb-native/blob/350d14fde5b24480403313cfe5044f6e4b25f6c9/src/connection_string.ts#L146-L206
2020
const HOSTS_REGEX = new RegExp(
21-
String.raw`^(?<protocol>mongodb(?:\+srv|)):\/\/(?:(?<username>[^:]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^\/?@]+)(?<rest>.*)`
21+
String.raw`^(?<protocol>mongodb(?:\+srv|)):\/\/(?:(?<username>[^:]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^\/?@]*)(?<rest>.*)`
2222
);
2323

2424
class CaseInsensitiveMap<K extends string = string> extends Map<K, string> {

test/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ describe('ConnectionString', () => {
114114
'mongodb+srv://a,b,c/',
115115
'mongodb+srv://a:12345/',
116116
'mongodbabc://localhost',
117-
'totallynotamongodb://localhost'
117+
'totallynotamongodb://localhost',
118+
'mongodb+srv://Y:X@'
118119
]) {
119120
it(`parsing ${uri} throws an MongoParseError`, () => {
120121
try {

0 commit comments

Comments
 (0)