Skip to content

Commit cd34f41

Browse files
bug #49353 [Cache] Only validate dbindex parameter when applicable (loevgaard)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Cache] Only validate dbindex parameter when applicable | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44215 | License | MIT It does not make sense to validate the path parameter when we _know_ that there can't be a dbindex. The problem with this validation is that it actually triggers when DSN looks something like: `redis://127.0.0.1:51148/` which happened to me in rare cases. Commits ------- c5e997b [Cache] Only validate dbindex parameter when applicable
2 parents 672751b + c5e997b commit cd34f41

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ private function doTestCreateConnection(string $uri)
6666
$this->assertTrue($redis->isConnected());
6767
$this->assertSame(0, $redis->getDbNum());
6868

69+
$redis = RedisAdapter::createConnection('redis://'.$uri.'/');
70+
$this->assertSame(0, $redis->getDbNum());
71+
6972
$redis = RedisAdapter::createConnection('redis://'.$uri.'/2');
7073
$this->assertSame(2, $redis->getDbNum());
7174

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static function createConnection(string $dsn, array $options = [])
148148
}
149149

150150
if (isset($params['host']) || isset($params['path'])) {
151-
if (!isset($params['dbindex']) && isset($params['path'])) {
151+
if (!isset($params['dbindex']) && isset($params['path']) && '/' !== $params['path']) {
152152
if (preg_match('#/(\d+)$#', $params['path'], $m)) {
153153
$params['dbindex'] = $m[1];
154154
$params['path'] = substr($params['path'], 0, -\strlen($m[0]));

0 commit comments

Comments
 (0)