10000 Cast empty string to null · symfony/symfony@1b4014f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b4014f

Browse files
Cast empty string to null
1 parent 3e1dd0d commit 1b4014f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static function createConnection($dsn, array $options = [])
103103
$params = preg_replace_callback('#^'.$scheme.':(//)?(?:(?:[^:@]*+:)?([^@]*+)@)?#', function ($m) use (&$auth) {
104104
if (isset($m[2])) {
105105
$auth = $m[2];
106+
107+
if ('' === $auth) {
108+
$auth = null;
109+
}
106110
}
107111

108112
return 'file:'.($m[1] ?? '');
@@ -182,7 +186,7 @@ public static function createConnection($dsn, array $options = [])
182186
throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$error.'.');
183187
}
184188

185-
if (($auth && !$redis->auth($auth))
189+
if ((null !== $auth && !$redis->auth($auth))
186190
|| ($params['dbindex'] && !$redis->select($params['dbindex']))
187191
|| ($params['read_timeout'] && !$redis->setOption(\Redis::OPT_READ_TIMEOUT, $params['read_timeout']))
188192
) {

src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
class ConnectionTest extends TestCase
2323
{
24+
/*
2425
public static function setUpBeforeClass(): void
2526
{
2627
try {
@@ -36,6 +37,7 @@ public static function setUpBeforeClass(): void
3637
self::markTestSkipped($e->getMessage());
3738
}
3839
}
40+
*/
3941

4042
public function testFromInvalidDsn()
4143
{

src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public function __construct(array $configuration, array $connectionCredentials =
5656
$this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP);
5757

5858
$auth = $connectionCredentials['auth'] ?? null;
59-
if ($auth && !$this->connection->auth($auth)) {
59+
if ('' === $auth) {
60+
$auth = null;
61+
}
62+
63+
if (null !== $auth && !$this->connection->auth($auth)) {
6064
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
6165
}
6266

0 commit comments

Comments
 (0)
0