From 00048a9c7303bc216f3e70bcfd0c69d35a711828 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 19 Apr 2021 18:05:59 +0200 Subject: [PATCH 1/5] [DependencyInjection][AliasDeprecatedPublicServicesPass] Noop when the service is private --- .../Compiler/AliasDeprecatedPublicServicesPass.php | 2 +- .../Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php index 802c407662..a44767de3a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AliasDeprecatedPublicServicesPass.php @@ -54,7 +54,7 @@ final class AliasDeprecatedPublicServicesPass extends AbstractRecursivePass $definition = $container->getDefinition($id); if (!$definition->isPublic() || $definition->isPrivate()) { - throw new InvalidArgumentException(sprintf('The "%s" service is private: it cannot have the "%s" tag.', $id, $this->tagName)); + continue; } $container diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php index b1f13ddb29..d03ece235a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php @@ -59,14 +59,13 @@ final class AliasDeprecatedPublicServicesPassTest extends TestCase public function testProcessWithNonPublicService() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The "foo" service is private: it cannot have the "container.private" tag.'); - $container = new ContainerBuilder(); $container ->register('foo') ->addTag('container.private', ['package' => 'foo/bar', 'version' => '1.2']); (new AliasDeprecatedPublicServicesPass())->process($container); + + $this->assertTrue($container->hasDefinition('foo')); } } From a1e0408d08a793aab1e14fb1c50ab901d3354583 Mon Sep 17 00:00:00 2001 From: Jack Thomas Date: Wed, 21 Apr 2021 23:34:53 -0400 Subject: [PATCH 2/5] [Cache] phpredis: Added full TLS support for RedisCluster --- .../Cache/Traits/RedisClusterNodeProxy.php | 48 +++++++++++++++++++ .../Component/Cache/Traits/RedisTrait.php | 10 ++-- 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php diff --git a/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php b/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php new file mode 100644 index 0000000000..7818f0b8df --- /dev/null +++ b/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Cache\Traits; + +/** + * This file acts as a wrapper to the \RedisCluster implementation so it can accept the same type of calls as + * individual \Redis objects. + * + * Calls are made to individual nodes via: RedisCluster->{method}($host, ...args)' + * according to https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#directed-node-commands + * + * @author Jack Thomas + * + * @internal + */ +class RedisClusterNodeProxy +{ + private $host; + private $redis; + + /** + * @param \RedisCluster|RedisClusterProxy $redis + */ + public function __construct(array $host, $redis) + { + $this->host = $host; + $this->redis = $redis; + } + + public function __call(string $method, array $args) + { + return $this->redis->{$method}($this->host, ...$args); + } + + public function scan(&$iIterator, $strPattern = null, $iCount = null) + { + return $this->redis->scan($iIterator, $this->host, $strPattern, $iCount); + } +} diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 9098df9465..6f22f33de5 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -41,6 +41,7 @@ trait RedisTrait 'redis_sentinel' => null, 'dbindex' => 0, 'failover' => 'none', + 'ssl' => null, // see https://php.net/context.ssl ]; private $redis; private $marshaller; @@ -187,7 +188,7 @@ trait RedisTrait } try { - @$redis->{$connect}($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout']); + @$redis->{$connect}($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ['stream' => $params['ssl'] ?? null]); set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; }); $isConnected = $redis->isConnected(); @@ -250,7 +251,7 @@ trait RedisTrait } try { - $redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $params['auth'] ?? ''); + $redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $params['auth'] ?? '', $params['ssl'] ?? null); } catch (\RedisClusterException $e) { throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e->getMessage()); } @@ -299,7 +300,7 @@ trait RedisTrait } $params['exceptions'] = false; - $redis = new $class($hosts, array_diff_key($params, self::$defaultConnectionOptions)); + $redis = new $class($hosts, array_diff_key($params, array_diff_key(self::$defaultConnectionOptions, ['ssl' => null]))); if (isset($params['redis_sentinel'])) { $redis->getConnection()->setSentinelTimeout($params['timeout']); } @@ -530,8 +531,7 @@ trait RedisTrait } elseif ($this->redis instanceof RedisClusterProxy || $this->redis instanceof \RedisCluster) { $hosts = []; foreach ($this->redis->_masters() as $host) { - $hosts[] = $h = new \Redis(); - $h->connect($host[0], $host[1]); + $hosts[] = new RedisClusterNodeProxy($host, $this->redis); } } From 9a130ae93e5b984276796f68d61e40738eed9aca Mon Sep 17 00:00:00 2001 From: Bert Ramakers Date: Thu, 18 Mar 2021 21:21:03 +0100 Subject: [PATCH 3/5] Fix issue 40507: Tabs as separators between tokens --- src/Symfony/Component/Yaml/Parser.php | 2 +- .../Component/Yaml/Tests/ParserTest.php | 73 +++++++++++++++---- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 6d0d523265..b3491f87c7 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -200,7 +200,7 @@ class Parser array_pop($this->refsBeingParsed); } } elseif ( - self::preg_match('#^(?P(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:( ++(?P.+))?$#u', rtrim($this->currentLine), $values) + self::preg_match('#^(?P(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P.+))?$#u', rtrim($this->currentLine), $values) && (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"])) ) { if ($context && 'sequence' == $context) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 1fa448dad5..9613503eef 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -52,26 +52,67 @@ class ParserTest extends TestCase return $this->loadTestsFromFixtureFiles('nonStringKeys.yml'); } - public function testTabsInYaml() + /** + * @dataProvider invalidIndentation + */ + public function testTabsAsIndentationInYaml(string $given, string $expectedMessage) { - // test tabs in YAML - $yamls = [ - "foo:\n bar", - "foo:\n bar", - "foo:\n bar", - "foo:\n bar", + $this->expectException(ParseException::class); + $this->expectExceptionMessage($expectedMessage); + $this->parser->parse($given); + } + + public function invalidIndentation(): array + { + return [ + [ + "foo:\n\tbar", + "A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar\").", + ], + [ + "foo:\n \tbar", + "A YAML file cannot contain tabs as indentation at line 2 (near \"\tbar\").", + ], + [ + "foo:\n\t bar", + "A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar\").", + ], + [ + "foo:\n \t bar", + "A YAML file cannot contain tabs as indentation at line 2 (near \"\t bar\").", + ], ]; + } - foreach ($yamls as $yaml) { - try { - $this->parser->parse($yaml); + /** + * @dataProvider validTokenSeparators + */ + public function testValidTokenSeparation(string $given, array $expected) + { + $actual = $this->parser->parse($given); + $this->assertEquals($expected, $actual); + } - $this->fail('YAML files must not contain tabs'); - } catch (\Exception $e) { - $this->assertInstanceOf(\Exception::class, $e, 'YAML files must not contain tabs'); - $this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs'); - } - } + public function validTokenSeparators(): array + { + return [ + [ + 'foo: bar', + ['foo' => 'bar'], + ], + [ + "foo:\tbar", + ['foo' => 'bar'], + ], + [ + "foo: \tbar", + ['foo' => 'bar'], + ], + [ + "foo:\t bar", + ['foo' => 'bar'], + ], + ]; } public function testEndOfTheDocumentMarker() From b6f8ed69ec93cb11c6ef4fa9abd8ee546a465f4d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 23 Apr 2021 09:16:57 +0200 Subject: [PATCH 4/5] use correct spelling when accessing the SMTP php.ini value --- .../Mailer/Tests/Transport/NativeTransportFactoryTest.php | 2 +- .../Component/Mailer/Transport/NativeTransportFactory.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Mailer/Tests/Transport/NativeTransportFactoryTest.php b/src/Symfony/Component/Mailer/Tests/Transport/NativeTransportFactoryTest.php index 630113dbdc..35f48ea4cc 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/NativeTransportFactoryTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/NativeTransportFactoryTest.php @@ -111,7 +111,7 @@ EOT; { self::$fakeConfiguration = [ 'sendmail_path' => $sendmailPath, - 'smtp' => $smtp, + 'SMTP' => $smtp, 'smtp_port' => $smtpPort, ]; diff --git a/src/Symfony/Component/Mailer/Transport/NativeTransportFactory.php b/src/Symfony/Component/Mailer/Transport/NativeTransportFactory.php index 358200b090..8afa53cc43 100644 --- a/src/Symfony/Component/Mailer/Transport/NativeTransportFactory.php +++ b/src/Symfony/Component/Mailer/Transport/NativeTransportFactory.php @@ -39,7 +39,7 @@ final class NativeTransportFactory extends AbstractTransportFactory // Only for windows hosts; at this point non-windows // host have already thrown an exception or returned a transport - $host = ini_get('smtp'); + $host = ini_get('SMTP'); $port = (int) ini_get('smtp_port'); if (!$host || !$port) { From 9826c059280275f8b55ff3056ce660479491ca0a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 23 Apr 2021 13:33:54 +0200 Subject: [PATCH 5/5] make fabbot happy --- src/Symfony/Component/Yaml/Parser.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 02181e05c7..9cee20dc38 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -227,7 +227,7 @@ class Parser } if (!\is_string($key) && !\is_int($key)) { - throw new ParseException(sprintf('%s keys are not supported. Quote your evaluable mapping keys instead.', is_numeric($key) ? 'Numeric' : 'Non-string'), $this->getRealCurrentLineNb() + 1, $this->currentLine); + throw new ParseException((is_numeric($key) ? 'Numeric' : 'Non-string').' keys are not supported. Quote your evaluable mapping keys instead.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } // Convert float keys to strings, to avoid being converted to integers by PHP @@ -242,7 +242,7 @@ class Parser $refName = substr(rtrim($values['value']), 1); if (!\array_key_exists($refName, $this->refs)) { if (false !== $pos = array_search($refName, $this->refsBeingParsed, true)) { - throw new ParseException(sprintf('Circular reference [%s, %s] detected for reference "%s".', implode(', ', \array_slice($this->refsBeingParsed, $pos)), $refName, $refName), $this->currentLineNb + 1, $this->currentLine, $this->filename); + throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$refName])), $refName), $this->currentLineNb + 1, $this->currentLine, $this->filename); } throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename); @@ -724,7 +724,7 @@ class Parser if (!\array_key_exists($value, $this->refs)) { if (false !== $pos = array_search($value, $this->refsBeingParsed, true)) { - throw new ParseException(sprintf('Circular reference [%s, %s] detected for reference "%s".', implode(', ', \array_slice($this->refsBeingParsed, $pos)), $value, $value), $this->currentLineNb + 1, $this->currentLine, $this->filename); + throw new ParseException(sprintf('Circular reference [%s] detected for reference "%s".', implode(', ', array_merge(\array_slice($this->refsBeingParsed, $pos), [$value])), $value), $this->currentLineNb + 1, $this->currentLine, $this->filename); } throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine, $this->filename); @@ -1217,7 +1217,7 @@ class Parser } } while ($this->moveToNextLine()); - throw new ParseException('Malformed inline YAML string'); + throw new ParseException('Malformed inline YAML string.'); } private function lexUnquotedString(int &$cursor): string @@ -1288,7 +1288,7 @@ class Parser } } while ($this->moveToNextLine()); - throw new ParseException('Malformed inline YAML string'); + throw new ParseException('Malformed inline YAML string.'); } private function consumeWhitespaces(int &$cursor): bool