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
8 changes: 7 additions & 1 deletion src/Tools/DsnParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ private function parseDatabaseUrlPath(array $url, array $params): array
return $params;
}

$url['path'] = $this->normalizeDatabaseUrlPath($url['path']);
if (isset($params['host'])) {
// Only normalize the path if a host is also available. Otherwise we might trim leading slashes
// from a pure dbname.
$url['path'] = $this->normalizeDatabaseUrlPath($url['path']);
}

// If we do not have a known DBAL driver, we do not know any connection URL path semantics to evaluate
// and therefore treat the path as a regular DBAL connection URL path.
Expand All @@ -131,6 +135,8 @@ private function parseDatabaseUrlPath(array $url, array $params): array
*/
private function normalizeDatabaseUrlPath(string $urlPath): string
{
assert($urlPath[0] === '/');

// Trim leading slash from URL path.
return substr($urlPath, 1);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Tools/DsnParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ public static function databaseUrls(): iterable
'dbname' => 'baz',
],
],
'quoted URL' => [
'"sqlite:////tmp/dbname.sqlite"',
['dbname' => '"sqlite:////tmp/dbname.sqlite"'],
],
'absolute path' => [
'/tmp/dbname.sqlite',
['dbname' => '/tmp/dbname.sqlite'],
],
];
}

Expand Down
Loading