Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore trailing slash in DSN #728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DependencyInjection/Configuration/RedisDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions tests/DependencyInjection/Configuration/RedisDsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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://[email protected]: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'],
];
}

Expand All @@ -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'],
];
Expand All @@ -112,7 +133,9 @@ public static function tlsValues(): array
{
return [
['redis://localhost', false],
['redis://localhost/', false],
['rediss://localhost', true],
['rediss://localhost/', true],
];
}

Expand All @@ -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://[email protected]: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],
];
Expand All @@ -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://[email protected]: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],
];
Expand All @@ -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'],
Expand All @@ -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://[email protected]:63790/10', null, 'pw'],
['redis://p%[email protected]:63790/10', null, 'p@w'],
['redis://mB(.z9},6o?zl>v!LM76A]lCg77,;[email protected]: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'],
Expand All @@ -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://[email protected]: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],
];
Expand All @@ -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://[email protected]: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'],
];
}

Expand Down
Loading