Skip to content

Commit 09e2cba

Browse files
Merge branch '5.4' into 6.3
* 5.4: fix detecting the database server version [Cache] Add url decoding of password in `RedisTrait` DSN [Serializer] Remove incompatible type declaration with PHP 7.2
2 parents 2f1a7ea + 5f942a9 commit 09e2cba

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

.github/workflows/integration-tests.yml

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ jobs:
4848
image: redis:6.2.8
4949
ports:
5050
- 16379:6379
51+
redis-authenticated:
52+
image: redis:6.2.8
53+
ports:
54+
- 16380:6379
55+
env:
56+
REDIS_ARGS: "--requirepass p@ssword"
5157
redis-cluster:
5258
image: grokzen/redis-cluster:6.2.8
5359
ports:
@@ -171,6 +177,7 @@ jobs:
171177
run: ./phpunit --group integration -v
172178
env:
173179
REDIS_HOST: 'localhost:16379'
180+
REDIS_AUTHENTICATED_HOST: 'localhost:16380'
174181
REDIS_CLUSTER_HOSTS: 'localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
175182
REDIS_SENTINEL_HOSTS: 'localhost:26379 localhost:26379 localhost:26379'
176183
REDIS_SENTINEL_SERVICE: redis_sentinel

src/Symfony/Component/Cache/Adapter/DoctrineDbalAdapter.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,14 @@ private function getServerVersion(): string
389389
return $this->serverVersion;
390390
}
391391

392-
if ($this->conn instanceof ServerVersionProvider) {
393-
return $this->conn->getServerVersion();
392+
if ($this->conn instanceof ServerVersionProvider || $this->conn instanceof ServerInfoAwareConnection) {
393+
return $this->serverVersion = $this->conn->getServerVersion();
394394
}
395395

396396
// The condition should be removed once support for DBAL <3.3 is dropped
397397
$conn = method_exists($this->conn, 'getNativeConnection') ? $this->conn->getNativeConnection() : $this->conn->getWrappedConnection();
398-
if ($conn instanceof ServerInfoAwareConnection) {
399-
return $this->serverVersion = $conn->getServerVersion();
400-
}
401398

402-
return $this->serverVersion = '0';
399+
return $this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
403400
}
404401

405402
private function addTableToSchema(Schema $schema): void

src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Cache\Traits\RedisTrait;
1717

18+
/**
19+
* @requires extension redis
20+
*/
1821
class RedisTraitTest extends TestCase
1922
{
20-
public static function setUpBeforeClass(): void
21-
{
22-
if (!getenv('REDIS_CLUSTER_HOSTS')) {
23-
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
24-
}
25-
}
26-
2723
/**
2824
* @dataProvider provideCreateConnection
2925
*/
@@ -42,6 +38,19 @@ public function testCreateConnection(string $dsn, string $expectedClass)
4238
self::assertInstanceOf($expectedClass, $connection);
4339
}
4440

41+
public function testUrlDecodeParameters()
42+
{
43+
if (!getenv('REDIS_AUTHENTICATED_HOST')) {
44+
self::markTestSkipped('REDIS_AUTHENTICATED_HOST env var is not defined.');
45+
}
46+
47+
$mock = self::getObjectForTrait(RedisTrait::class);
48+
$connection = $mock::createConnection('redis://:p%40ssword@'.getenv('REDIS_AUTHENTICATED_HOST'));
49+
50+
self::assertInstanceOf(\Redis::class, $connection);
51+
self::assertSame('p@ssword', $connection->getAuth());
52+
}
53+
4554
public static function provideCreateConnection(): array
4655
{
4756
$hosts = array_map(fn ($host) => sprintf('host[%s]', $host), explode(' ', getenv('REDIS_CLUSTER_HOSTS')));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
101101
$params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:(?<user>[^:@]*+):)?(?<password>[^@]*+)@)?#', function ($m) use (&$auth) {
102102
if (isset($m['password'])) {
103103
if (\in_array($m['user'], ['', 'default'], true)) {
104-
$auth = $m['password'];
104+
$auth = rawurldecode($m['password']);
105105
} else {
106-
$auth = [$m['user'], $m['password']];
106+
$auth = [rawurldecode($m['user']), rawurldecode($m['password'])];
107107
}
108108

109109
if ('' === $auth) {

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ private static function parseDsn(string $dsn, array &$options): array
249249
$url = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:(?<user>[^:@]*+):)?(?<password>[^@]*+)@)?#', function ($m) use (&$auth) {
250250
if (isset($m['password'])) {
251251
if (!\in_array($m['user'], ['', 'default'], true)) {
252-
$auth['user'] = $m['user'];
252+
$auth['user'] = rawurldecode($m['user']);
253253
}
254254

255-
$auth['pass'] = $m['password'];
255+
$auth['pass'] = rawurldecode($m['password']);
256256
}
257257

258258
return 'file:'.($m[1] ?? '');

src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,10 @@ interface PropertyDummyInterface
641641

642642
class PropertyDiscriminatedDummyOne implements PropertyDummyInterface
643643
{
644-
public string $url = 'URL_ONE';
644+
public $url = 'URL_ONE';
645645
}
646646

647647
class PropertyDiscriminatedDummyTwo implements PropertyDummyInterface
648648
{
649-
public string $url = 'URL_TWO';
649+
public $url = 'URL_TWO';
650650
}

0 commit comments

Comments
 (0)