From 2378a89332dfb4c16ae952186157bd9edc3df1f0 Mon Sep 17 00:00:00 2001 From: Roman Martinuk Date: Sun, 14 Nov 2021 11:16:02 +0300 Subject: [PATCH] [Cache] fix dbindex Redis --- .../Component/Cache/Tests/Adapter/RedisAdapterTest.php | 1 + src/Symfony/Component/Cache/Traits/RedisTrait.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php index d961187aeca3a..7bb16573db32f 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php @@ -112,6 +112,7 @@ public function testInvalidCreateConnection(string $dsn) public function provideInvalidCreateConnection(): array { return [ + ['redis://localhost/foo'], ['foo://localhost'], ['redis://'], ]; diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 990678165624a..5365a53b18f15 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -147,9 +147,13 @@ public static function createConnection($dsn, array $options = []) } if (isset($params['host']) || isset($params['path'])) { - if (!isset($params['dbindex']) && isset($params['path']) && preg_match('#/(\d+)$#', $params['path'], $m)) { - $params['dbindex'] = $m[1]; - $params['path'] = substr($params['path'], 0, -\strlen($m[0])); + if (!isset($params['dbindex']) && isset($params['path'])) { + if (preg_match('#/(\d+)$#', $params['path'], $m)) { + $params['dbindex'] = $m[1]; + $params['path'] = substr($params['path'], 0, -\strlen($m[0])); + } else { + throw new InvalidArgumentException(sprintf('Invalid Redis DSN: "%s", the "dbindex" parameter must be a number.', $dsn)); + } } if (isset($params['host'])) {