Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9f2866f

Browse filesBrowse files
committed
Do not set host if unix_socket is set
1 parent b19f7c1 commit 9f2866f
Copy full SHA for 9f2866f

File tree

2 files changed

+16
-13
lines changed
Filter options

2 files changed

+16
-13
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php
+15-12Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,21 @@ private function buildDsnFromUrl(string $dsnOrUrl): string
491491
case 'pgsql':
492492
$dsn = $driver.':';
493493

494-
if (isset($params['host']) && '' !== $params['host']) {
494+
$hasSocket = false;
495+
if ('mysql' === $driver && isset($params['query']) && '' !== $params['query']) {
496+
$queryParams = [];
497+
parse_str($params['query'], $queryParams);
498+
if (isset($queryParams['unix_socket']) && '' !== $queryParams['unix_socket']) {
499+
$dsn .= 'unix_socket='.$queryParams['unix_socket'].';';
500+
$hasSocket = true;
501+
}
502+
503+
if (isset($queryParams['charset']) && '' !== $queryParams['charset']) {
504+
$dsn .= 'charset='.$queryParams['charset'].';';
505+
}
506+
}
507+
508+
if (!$hasSocket && isset($params['host']) && '' !== $params['host']) {
495509
$dsn .= 'host='.$params['host'].';';
496510
}
497511

@@ -504,17 +518,6 @@ private function buildDsnFromUrl(string $dsnOrUrl): string
504518
$dsn .= 'dbname='.$dbName.';';
505519
}
506520

507-
if ('mysql' === $driver && isset($params['query']) && '' !== $params['query']) {
508-
$queryParams = [];
509-
parse_str($params['query'], $queryParams);
510-
if (isset($queryParams['unix_socket']) && '' !== $queryParams['unix_socket']) {
511-
$dsn .= 'unix_socket='.$queryParams['unix_socket'].';';
512-
}
513-
514-
if (isset($queryParams['charset']) && '' !== $queryParams['charset']) {
515-
$dsn .= 'charset='.$queryParams['charset'].';';
516-
}
517-
}
518521

519522
return $dsn;
520523

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
+1-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.