diff --git a/src/DependencyInjection/Configuration/RedisDsn.php b/src/DependencyInjection/Configuration/RedisDsn.php index d9a551f3..2330f493 100644 --- a/src/DependencyInjection/Configuration/RedisDsn.php +++ b/src/DependencyInjection/Configuration/RedisDsn.php @@ -158,6 +158,10 @@ protected function parseDsn(string $dsn): void $dsn = $matches[1]; } + if ($dsn[-1] === '/') { + $dsn = substr($dsn, 0, -1); // remove a trailing slash if present + } + if (preg_match('#^([^:]+)(:(\d+|%[^%]+%))?$#', $dsn, $matches)) { if (!empty($matches[1])) { // parse host/ip or socket diff --git a/tests/DependencyInjection/Configuration/RedisDsnTest.php b/tests/DependencyInjection/Configuration/RedisDsnTest.php index 36fb738a..a671bc7b 100644 --- a/tests/DependencyInjection/Configuration/RedisDsnTest.php +++ b/tests/DependencyInjection/Configuration/RedisDsnTest.php @@ -23,46 +23,63 @@ public static function hostValues(): array { return [ ['redis://localhost', 'localhost'], + ['redis://localhost/', 'localhost'], ['redis://localhost/1', 'localhost'], ['redis://localhost:63790', 'localhost'], + ['redis://localhost:63790/', 'localhost'], ['redis://localhost:63790/10', 'localhost'], ['redis://pw@localhost:63790/10', 'localhost'], ['redis://127.0.0.1', '127.0.0.1'], + ['redis://127.0.0.1/', '127.0.0.1'], ['redis://127.0.0.1/1', '127.0.0.1'], ['redis://127.0.0.1:63790', '127.0.0.1'], + ['redis://127.0.0.1:63790/', '127.0.0.1'], ['redis://127.0.0.1:63790/10', '127.0.0.1'], ['redis://pw@127.0.0.1:63790/10', '127.0.0.1'], ['redis://[::1]', '::1'], + ['redis://[::1]/', '::1'], ['redis://[::1]/1', '::1'], ['redis://[::1]:63790', '::1'], + ['redis://[::1]:63790/', '::1'], ['redis://[::1]:63790/10', '::1'], ['redis://pw@[::1]:63790/10', '::1'], ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]', '1050:0000:0000:0000:0005:0600:300c:326b'], + ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]/', '1050:0000:0000:0000:0005:0600:300c:326b'], ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]/1', '1050:0000:0000:0000:0005:0600:300c:326b'], ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]:63790', '1050:0000:0000:0000:0005:0600:300c:326b'], + ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]:63790/', '1050:0000:0000:0000:0005:0600:300c:326b'], ['redis://[1050:0000:0000:0000:0005:0600:300c:326b]:63790/10', '1050:0000:0000:0000:0005:0600:300c:326b'], ['redis://pw@[1050:0000:0000:0000:0005:0600:300c:326b]:63790/10', '1050:0000:0000:0000:0005:0600:300c:326b'], ['redis://[1050:0:0:0:5:600:300c:326b]', '1050:0:0:0:5:600:300c:326b'], + ['redis://[1050:0:0:0:5:600:300c:326b]/', '1050:0:0:0:5:600:300c:326b'], ['redis://[1050:0:0:0:5:600:300c:326b]/1', '1050:0:0:0:5:600:300c:326b'], ['redis://[1050:0:0:0:5:600:300c:326b]:63790', '1050:0:0:0:5:600:300c:326b'], + ['redis://[1050:0:0:0:5:600:300c:326b]:63790/', '1050:0:0:0:5:600:300c:326b'], ['redis://[1050:0:0:0:5:600:300c:326b]:63790/10', '1050:0:0:0:5:600:300c:326b'], ['redis://pw@[1050:0:0:0:5:600:300c:326b]:63790/10', '1050:0:0:0:5:600:300c:326b'], ['redis://[ff06:0:0:0:0:0:0:c3]', 'ff06:0:0:0:0:0:0:c3'], + ['redis://[ff06:0:0:0:0:0:0:c3]/', 'ff06:0:0:0:0:0:0:c3'], ['redis://[ff06:0:0:0:0:0:0:c3]/1', 'ff06:0:0:0:0:0:0:c3'], ['redis://[ff06:0:0:0:0:0:0:c3]:63790', 'ff06:0:0:0:0:0:0:c3'], + ['redis://[ff06:0:0:0:0:0:0:c3]:63790/', 'ff06:0:0:0:0:0:0:c3'], ['redis://[ff06:0:0:0:0:0:0:c3]:63790/10', 'ff06:0:0:0:0:0:0:c3'], ['redis://pw@[ff06:0:0:0:0:0:0:c3]:63790/10', 'ff06:0:0:0:0:0:0:c3'], ['redis://[ff06::c3]', 'ff06::c3'], + ['redis://[ff06::c3]/', 'ff06::c3'], ['redis://[ff06::c3]/1', 'ff06::c3'], ['redis://[ff06::c3]:63790', 'ff06::c3'], + ['redis://[ff06::c3]:63790/', 'ff06::c3'], ['redis://[ff06::c3]:63790/10', 'ff06::c3'], ['redis://pw@[ff06::c3]:63790/10', 'ff06::c3'], ['redis://%redis_host%', '%redis_host%'], + ['redis://%redis_host%/', '%redis_host%'], ['redis://%redis_host%/%redis_db%', '%redis_host%'], ['redis://%redis_host%:%redis_port%', '%redis_host%'], + ['redis://%redis_host%:%redis_port%/', '%redis_host%'], ['redis://%redis_host%:%redis_port%/%redis_db%', '%redis_host%'], ['redis://%redis_pass%@%redis_host%:%redis_port%/%redis_db%', '%redis_host%'], ['rediss://localhost', 'localhost'], + ['rediss://localhost/', 'localhost'], ]; } @@ -83,13 +100,17 @@ public static function socketValues(): array { return [ ['redis:///redis.sock', '/redis.sock'], + ['redis:///redis.sock/', '/redis.sock'], ['redis:///redis.sock/1', '/redis.sock'], ['redis:///redis.sock:63790', '/redis.sock'], + ['redis:///redis.sock:63790/', '/redis.sock'], ['redis:///redis.sock:63790/10', '/redis.sock'], ['redis://pw@/redis.sock:63790/10', '/redis.sock'], ['redis:///var/run/redis/redis-1.sock', '/var/run/redis/redis-1.sock'], + ['redis:///var/run/redis/redis-1.sock/', '/var/run/redis/redis-1.sock'], ['redis:///var/run/redis/redis-1.sock/1', '/var/run/redis/redis-1.sock'], ['redis:///var/run/redis/redis-1.sock:63790', '/var/run/redis/redis-1.sock'], + ['redis:///var/run/redis/redis-1.sock:63790/', '/var/run/redis/redis-1.sock'], ['redis:///var/run/redis/redis-1.sock:63790/10', '/var/run/redis/redis-1.sock'], ['redis://pw@/var/run/redis/redis-1.sock:63790/10', '/var/run/redis/redis-1.sock'], ]; @@ -112,7 +133,9 @@ public static function tlsValues(): array { return [ ['redis://localhost', false], + ['redis://localhost/', false], ['rediss://localhost', true], + ['rediss://localhost/', true], ]; } @@ -128,22 +151,30 @@ public static function portValues(): array { return [ ['redis://localhost', 6379], + ['redis://localhost/', 6379], ['redis://localhost/1', 6379], ['rediss://localhost:6380', 6380], + ['rediss://localhost:6380/', 6380], ['redis://localhost:63790', 63790], + ['redis://localhost:63790/', 63790], ['redis://localhost:63790/10', 63790], ['redis://pw@localhost:63790/10', 63790], ['redis://127.0.0.1', 6379], + ['redis://127.0.0.1/', 6379], ['redis://127.0.0.1/1', 6379], ['redis://127.0.0.1:63790', 63790], + ['redis://127.0.0.1:63790/', 63790], ['redis://127.0.0.1:63790/10', 63790], ['redis://pw@127.0.0.1:63790/10', 63790], ['redis://%redis_host%:%redis_port%', '%redis_port%'], + ['redis://%redis_host%:%redis_port%/', '%redis_port%'], ['redis://%redis_host%:%redis_port%/%redis_db%', '%redis_port%'], ['redis://%redis_pass%@%redis_host%:%redis_port%/%redis_db%', '%redis_port%'], ['redis:///redis.sock', 0], + ['redis:///redis.sock/', 0], ['redis:///redis.sock/1', 0], ['redis:///redis.sock:63790', 0], + ['redis:///redis.sock:63790/', 0], ['redis:///redis.sock:63790/10', 0], ['redis://pw@/redis.sock:63790/10', 0], ]; @@ -165,26 +196,34 @@ public static function databaseValues(): array { return [ ['redis://localhost', null], + ['redis://localhost/', null], ['redis://localhost/0', 0], ['redis://localhost/1', 1], ['redis://localhost:63790', null], + ['redis://localhost:63790/', null], ['redis://localhost:63790/10', 10], ['redis://pw@localhost:63790/10', 10], ['redis://127.0.0.1', null], + ['redis://127.0.0.1/', null], ['redis://127.0.0.1/0', 0], ['redis://127.0.0.1/1', 1], ['redis://127.0.0.1:63790', null], + ['redis://127.0.0.1:63790/', null], ['redis://127.0.0.1:63790/10', 10], ['redis://pw@127.0.0.1:63790/10', 10], ['redis://%redis_host%', null], + ['redis://%redis_host%/', null], ['redis://%redis_host%/%redis_db%', '%redis_db%'], ['redis://%redis_host%:%redis_port%', null], + ['redis://%redis_host%:%redis_port%/', null], ['redis://%redis_host%:%redis_port%/%redis_db%', '%redis_db%'], ['redis://pw@%redis_host%:%redis_port%/%redis_db%', '%redis_db%'], ['redis:///redis.sock', null], + ['redis:///redis.sock/', null], ['redis:///redis.sock/0', 0], ['redis:///redis.sock/1', 1], ['redis:///redis.sock:63790', null], + ['redis:///redis.sock:63790/', null], ['redis:///redis.sock:63790/10', 10], ['redis://pw@/redis.sock:63790/10', 10], ]; @@ -206,6 +245,7 @@ public static function authenticationParametersValues(): array { return [ ['redis://localhost', null, null], + ['redis://localhost/', null, null], ['redis://localhost/1', null, null], ['redis://pw@localhost:63790/10', null, 'pw'], ['redis://:pw@localhost:63790/10', null, 'pw'], @@ -215,14 +255,18 @@ public static function authenticationParametersValues(): array ['redis://p%40w@localhost:63790/10', null, 'p@w'], ['redis://mB(.z9},6o?zl>v!LM76A]lCg77,;.@localhost:63790/10', null, 'mB(.z9},6o?zl>v!LM76A]lCg77,;.'], ['redis://127.0.0.1', null, null], + ['redis://127.0.0.1/', null, null], ['redis://127.0.0.1/1', null, null], ['redis://pw@127.0.0.1:63790/10', null, 'pw'], ['redis://p%40w@127.0.0.1:63790/10', null, 'p@w'], ['redis://mB(.z9},6o?zl>v!LM76A]lCg77,;.@127.0.0.1:63790/10', null, 'mB(.z9},6o?zl>v!LM76A]lCg77,;.'], ['redis://%redis_host%', null, null], + ['redis://%redis_host%/', null, null], ['redis://%redis_host%/%redis_db%', null, null], ['redis://%redis_pass%@%redis_host%:%redis_port%', null, '%redis_pass%'], + ['redis://%redis_pass%@%redis_host%:%redis_port%/', null, '%redis_pass%'], ['redis:///redis.sock', null, null], + ['redis:///redis.sock/', null, null], ['redis:///redis.sock/1', null, null], ['redis://pw@/redis.sock/10', null, 'pw'], ['redis://p%40w@/redis.sock/10', null, 'p@w'], @@ -243,22 +287,29 @@ public static function isValidValues(): array { return [ ['redis://localhost', true], + ['redis://localhost/', true], ['rediss://localhost', true], + ['rediss://localhost/', true], ['redis://localhost/1', true], ['redis://pw@localhost:63790/10', true], ['redis://127.0.0.1', true], + ['redis://127.0.0.1/', true], ['redis://127.0.0.1/1', true], ['redis://pw@127.0.0.1:63790/10', true], ['redis:///redis.sock', true], + ['redis:///redis.sock/', true], ['redis:///redis.sock/1', true], ['redis://pw@/redis.sock/10', true], ['redis://pw@/redis.sock/10', true], ['redis://%redis_host%', true], + ['redis://%redis_host%/', true], ['redis://%redis_host%/%redis_db%', true], ['redis://%redis_host%:%redis_port%', true], + ['redis://%redis_host%:%redis_port%/', true], ['redis://%redis_host%:%redis_port%/%redis_db%', true], ['redis://%redis_pass%@%redis_host%:%redis_port%/%redis_db%', true], ['localhost', false], + ['localhost/', false], ['localhost/1', false], ['pw@localhost:63790/10', false], ]; @@ -281,16 +332,20 @@ public static function parameterValues(): array { return [ ['redis://localhost', null, null], + ['redis://localhost/', null, null], ['redis://localhost/1?weight=1&alias=master', 1, 'master'], ['redis://pw@localhost:63790/10?alias=master&weight=2', 2, 'master'], ['redis://127.0.0.1?weight=3', 3, null], + ['redis://127.0.0.1/?weight=3', 3, null], ['redis://127.0.0.1/1?alias=master&weight=4', 4, 'master'], ['redis://pw@127.0.0.1:63790/10?weight=5&alias=master', 5, 'master'], ['redis:///redis.sock?weight=6&alias=master', 6, 'master'], + ['redis:///redis.sock/?weight=6&alias=master', 6, 'master'], ['redis:///redis.sock/1?weight=7', 7, null], ['redis://pw@/redis.sock/10?weight=8&alias=master', 8, 'master'], ['redis://pw@/redis.sock/10?alias=master&weight=9', 9, 'master'], ['redis://localhost?alias=master', null, 'master'], + ['redis://localhost/?alias=master', null, 'master'], ]; }