Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function withFreshQueryLog($callback)
protected function getDefaultDatabaseName(string $dsn, array $config): string
{
if (empty($config['database'])) {
if (! preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+\\/([^?&]+)/s', $dsn, $matches)) {
if (! preg_match('/^mongodb(?:[+]srv)?:\\/\\/.+?\\/([^?&]+)/s', $dsn, $matches)) {
throw new InvalidArgumentException('Database is not properly configured.');
}

Expand Down
6 changes: 6 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public static function dataConnectionConfig(): Generator
'expectedDatabaseName' => 'tests',
'config' => ['dsn' => 'mongodb://some-host:12345/tests'],
];

yield 'Database is extracted from DSN with CA path in options' => [
'expectedUri' => 'mongodb://some-host:12345/tests?tls=true&tlsCAFile=/path/to/ca.pem&retryWrites=false',
'expectedDatabaseName' => 'tests',
'config' => ['dsn' => 'mongodb://some-host:12345/tests?tls=true&tlsCAFile=/path/to/ca.pem&retryWrites=false'],
];
}

#[DataProvider('dataConnectionConfig')]
Expand Down
Loading