Skip to content

Commit 1b46769

Browse files
committed
fix(utils): getHost: reduce calls by combining regex
1 parent 64dc781 commit 1b46769

File tree

1 file changed

+2
-1
lines changed
  • packages/mongodb-memory-server-core/src/util

1 file changed

+2
-1
lines changed

packages/mongodb-memory-server-core/src/util/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export function generateDbName(dbName?: string): string {
2020
* @param {string} uri mongodb URI
2121
*/
2222
export function getHost(uri: string): string {
23-
return uri.replace('mongodb://', '').replace(/\/.*/, '');
23+
// this will turn "mongodb://user:pass@localhost:port/authdb?queryoptions=1" to "localhost:port"
24+
return uri.replace(/(?:^mongodb:\/{2})|(?:\/.*$)|(?:.*@)/gim, '');
2425
}
2526

2627
/**

0 commit comments

Comments
 (0)