8000 Do not set host if unix_socket is set · symfony/symfony@fff16a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit fff16a3

Browse files
bcremerNyholm
authored andcommitted
Do not set host if unix_socket is set
1 parent 9174365 commit fff16a3

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -491,31 +491,33 @@ private function buildDsnFromUrl(string $dsnOrUrl): string
491491
case 'pgsql':
492492
$dsn = $driver.':';
493493

494-
if (isset($params['host']) && '' !== $params['host']) {
495-
$dsn .= 'host='.$params['host'].';';
496-
}
497-
498-
if (isset($params['port']) && '' !== $params['port']) {
499-
$dsn .= 'port='.$params['port'].';';
500-
}
501-
502-
if (isset($params['path'])) {
503-
$dbName = substr($params['path'], 1); // Remove the leading slash
504-
$dsn .= 'dbname='.$dbName.';';
505-
}
506-
494+
$hasSocket = false;
507495
if ('mysql' === $driver && isset($params['query']) && '' !== $params['query']) {
508496
$queryParams = [];
509497
parse_str($params['query'], $queryParams);
510498
if (isset($queryParams['unix_socket']) && '' !== $queryParams['unix_socket']) {
511499
$dsn .= 'unix_socket='.$queryParams['unix_socket'].';';
500+
$hasSocket = true;
512501
}
513502

514503
if (isset($queryParams['charset']) && '' !== $queryParams['charset']) {
515504
$dsn .= 'charset='.$queryParams['charset'].';';
516505
}
517506
}
518507

508+
if (!$hasSocket && isset($params['host']) && '' !== $params['host']) {
509+
$dsn .= 'host='.$params['host'].';';
510+
}
511+
512+
if (isset($params['port']) && '' !== $params['port']) {
513+
$dsn .= 'port='.$params['port'].';';
514+
}
515+
516+
if (isset($params['path'])) {
517+
$dbName = substr($params['path'], 1); // Remove the leading slash
518+
$dsn .= 'dbname='.$dbName.';';
519+
}
520+
519521
return $dsn;
520522

521523
case 'sqlite':

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function testUrlDsn($url, $expectedDsn, $expectedUser = null, $expectedPa
332332
public function provideUrlDsnPairs()
333333
{
334334
yield ['mysql://localhost/test', 'mysql:host=localhost;dbname=test;'];
335-
yield ['mysql://localhost/test?unix_socket=socket.sock&charset=utf8mb4', 'mysql:host=localhost;dbname=test;unix_socket=socket.sock;charset=utf8mb4;'];
335+
yield ['mysql://localhost/test?unix_socket=socket.sock&charset=utf8mb4', 'mysql:unix_socket=socket.sock;charset=utf8mb4;dbname=test;'];
336336
yield ['mysql://localhost:56/test', 'mysql:host=localhost;port=56;dbname=test;'];
337337
yield ['mysql2://root:pwd@localhost/test', 'mysql:host=localhost;dbname=test;', 'root', 'pwd'];
338338
yield ['postgres://localhost/test', 'pgsql:host=localhost;dbname=test;'];

0 commit comments

Comments
 (0)
0