Skip to content

Commit 1ae327f

Browse files
fix: quote schema special chars
1 parent 0fed657 commit 1ae327f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Doctrine/SchemaConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ private function ensurePostgreSql(): void
5050
private function applySearchPath(string $schema): void
5151
{
5252
if ($this->_conn !== null) {
53+
$schema = $this->getDatabasePlatform()->quoteIdentifier($schema);
54+
5355
$this->_conn->exec('SET search_path TO ' . $schema);
5456
}
5557
}

tests/Doctrine/SchemaConnectionTest.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testConnectSetsSearchPath(): void
2323

2424
$driverConnection->expects($this->once())
2525
->method('exec')
26-
->with('SET search_path TO test_schema');
26+
->with('SET search_path TO "test_schema"');
2727

2828
$driver = $this->createMock(Driver::class);
2929

@@ -49,6 +49,38 @@ public function testConnectSetsSearchPath(): void
4949
self::assertTrue($result);
5050
}
5151

52+
public function testConnectSetsSearchPathWithSpecialChars(): void
53+
{
54+
$driverConnection = $this->createMock(DriverConnection::class);
55+
56+
$driverConnection->expects($this->once())
57+
->method('exec')
58+
->with('SET search_path TO "test-schema/foo"');
59+
60+
$driver = $this->createMock(Driver::class);
61+
62+
$driver->method('connect')->willReturn($driverConnection);
63+
64+
$platform = new PostgreSQLPlatform();
65+
$connection = $this->getMockBuilder(SchemaConnection::class)
66+
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
67+
->onlyMethods(['getDatabasePlatform', 'fetchOne'])
68+
->getMock();
69+
70+
$connection->method('getDatabasePlatform')->willReturn($platform);
71+
$connection->method('fetchOne')->willReturn(true);
72+
73+
$resolver = new BaggageSchemaResolver();
74+
75+
$resolver->setSchema('test-schema/foo');
76+
77+
SchemaConnection::setSchemaResolver($resolver);
78+
79+
$result = $connection->connect();
80+
81+
self::assertTrue($result);
82+
}
83+
5284
public function testConnectSkipsWhenNoSchema(): void
5385
{
5486
$driverConnection = $this->createMock(DriverConnection::class);

0 commit comments

Comments
 (0)