Skip to content

Commit ee38f85

Browse files
committed
Fix DSN parsing
1 parent e2ff7e1 commit ee38f85

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pkg/dbal/DbalConnectionFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ private function parseDsn(string $dsn, ?array $config = null): array
153153

154154
$dsnParser = new DsnParser($supported);
155155

156+
// replace scheme with the matching one from the supported list, but the prefixes there are "pdo-" not "pdo_"
157+
$dsn = preg_replace(
158+
'/^' . preg_quote($parsedDsn->getScheme(), '/') . '(:|:\/\/)/',
159+
str_replace('_','-', $supported[$parsedDsn->getScheme()]) . '$1',
160+
$dsn,
161+
);
162+
156163
return [
157164
'lazy' => true,
158165
'connection' => $dsnParser->parse($dsn),

pkg/dbal/Tests/DbalConnectionFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testShouldParseSqliteAbsolutePathDSN()
5555

5656
$config = $context->getConfig();
5757
$this->assertArrayHasKey('connection', $config);
58-
$this->assertArrayHasKey('driver', $config['connection']);
59-
$this->assertEquals('pdo_sqlite:////tmp/some.sq3', $config['connection']['url']);
58+
$this->assertArrayHasKey('path', $config['connection']);
59+
$this->assertEquals('/tmp/some.sq3', $config['connection']['path']);
6060
}
6161
}

0 commit comments

Comments
 (0)