diff --git a/CHANGELOG-6.1.md b/CHANGELOG-6.1.md index ecfb505d25ca3..933e6b1d88dae 100644 --- a/CHANGELOG-6.1.md +++ b/CHANGELOG-6.1.md @@ -7,6 +7,34 @@ in 6.1 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v6.1.0...v6.1.1 +* 6.1.2 (2022-06-26) + + * bug #46779 [String] Add an invariable word in french (lemonlab) + * bug #46765 [Serializer] Fix denormalization union types with constructor (Gwemox) + * bug #46769 [HttpKernel] Fix a PHP 8.1 deprecation notice in HttpCache (mpdude) + * bug #46760 Fix double authentication via RememberMe resulting in wrong RememberMe cookie being set in client (heiglandreas) + * bug #46766 Initially set user null. (mogilvie) + * bug #46735 [Messenger] Do not log the message object itself (ajardin) + * bug #46748 [Security] Fix legacy impersonation system (dunglas) + * bug #46747 Fix global state pollution between tests run with ApplicationTester (Seldaek) + * bug #46730 [Intl] Fix the IntlDateFormatter::formatObject signature (damienalexandre) + * bug #46668 [FrameworkBundle] Lower JsonSerializableNormalizer priority (aprat84) + * bug #46711 [PhpUnitBridge] Exclude from baseline generation deprecations triggered in legacy test (mondrake) + * bug #46678 [HttpFoundation] Update "[Session] Overwrite invalid session id" to only validate when files session storage is used (alexpott) + * bug #46665 [HttpClient] Fix Copy as curl with base uri (HypeMC) + * bug #46670 [HttpClient] Fix json encode flags usage in copy-as-curl generation (welcoMattic) + * bug #45861 [Serializer] Try all possible denormalization route with union types when ALLOW_EXTRA_ATTRIBUTES=false (T-bond) + * bug #46676 [DoctrineBridge] Extend type guessing on enum fields (Gigino Chianese) + * bug #46699 [Cache] Respect $save option in all adapters (jrjohnson) + * bug #46697 [HttpKernel] Disable session tracking while collecting profiler data (nicolas-grekas) + * bug #46704 Allow passing null in twig_is_selected_choice (raziel057) + * bug #46684 [MonologBridge] Fixed support of elasticsearch 7.+ in ElasticsearchLogstashHandler (lyrixx) + * bug #46650 [WebProfilerBundle] Bump http-kernel requirement to ^6.1 (ostrolucky) + * bug #46646 [Messenger] move resetting services at worker stopped into listener (Thomas Talbot) + * bug #46611 [PropertyInfo] Fix multi phpdoc covered promoted properties (ostrolucky, simPod) + * bug #46368 [Mailer] Fix for missing sender name in case with usage of the EnvelopeListener (bobahvas) + * bug #46603 [Mailer] Fix Error Handling for OhMySMTP Bridge (paul-oms) + * 6.1.1 (2022-06-09) * bug #46570 [HttpClient][WebProfilerBundle] Catch errors when encoding body for c… (Phillip Look) diff --git a/phpunit b/phpunit index 7ca6ceeccbee8..e26fecd73cc9d 100755 --- a/phpunit +++ b/phpunit @@ -13,7 +13,7 @@ if (!getenv('SYMFONY_PHPUNIT_VERSION')) { if (\PHP_VERSION_ID < 70200) { putenv('SYMFONY_PHPUNIT_VERSION=7.5'); } elseif (\PHP_VERSION_ID < 70300) { - putenv('SYMFONY_PHPUNIT_VERSION=8.5'); + putenv('SYMFONY_PHPUNIT_VERSION=8.5.26'); } else { putenv('SYMFONY_PHPUNIT_VERSION=9.5'); } diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 2126dad1bade6..8f314cd98f5e1 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -135,17 +135,18 @@ public function getTypes(string $class, string $property, array $context = []): } if ($metadata->hasField($property)) { - $nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property); - if (null !== $enumClass = $metadata->getFieldMapping($property)['enumType'] ?? null) { - return [new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass)]; - } - $typeOfField = $metadata->getTypeOfField($property); if (!$builtinType = $this->getPhpType($typeOfField)) { return null; } + $nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property); + $enumType = null; + if (null !== $enumClass = $metadata->getFieldMapping($property)['enumType'] ?? null) { + $enumType = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass); + } + switch ($builtinType) { case Type::BUILTIN_TYPE_OBJECT: switch ($typeOfField) { @@ -171,11 +172,23 @@ public function getTypes(string $class, string $property, array $context = []): switch ($typeOfField) { case Types::ARRAY: case 'json_array': + // return null if $enumType is set, because we can't determine if collectionKeyType is string or int + if ($enumType) { + return null; + } + return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true)]; case Types::SIMPLE_ARRAY: - return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))]; + return [new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, new Type(Type::BUILTIN_TYPE_INT), $enumType ?? new Type(Type::BUILTIN_TYPE_STRING))]; } + break; + case Type::BUILTIN_TYPE_INT: + case Type::BUILTIN_TYPE_STRING: + if ($enumType) { + return [$enumType]; + } + break; } return [new Type($builtinType, $nullable)]; diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 9416c64048470..2f9e8ccf7361a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -127,6 +127,9 @@ public function testExtractEnum() } $this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', [])); $this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', [])); + $this->assertEquals(null, $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', [])); + $this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, EnumInt::class))], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumIntArray', [])); + $this->assertEquals(null, $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', [])); } public function typesProvider() diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEnum.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEnum.php index 467522cbd3914..fd5271fc47730 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEnum.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineEnum.php @@ -35,4 +35,19 @@ class DoctrineEnum * @Column(type="integer", enumType="Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt") */ protected $enumInt; + + /** + * @Column(type="array", enumType="Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumString") + */ + protected $enumStringArray; + + /** + * @Column(type="simple_array", enumType="Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt") + */ + protected $enumIntArray; + + /** + * @Column(type="custom_foo", enumType="Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt") + */ + protected $enumCustom; } diff --git a/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php b/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php index 4c898572ec5a6..064a0fca43a21 100644 --- a/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php @@ -54,13 +54,14 @@ class ElasticsearchLogstashHandler extends AbstractHandler private string $endpoint; private string $index; private HttpClientInterface $client; + private string $elasticsearchVersion; /** * @var \SplObjectStorage */ private \SplObjectStorage $responses; - public function __construct(string $endpoint = 'http://127.0.0.1:9200', string $index = 'monolog', HttpClientInterface $client = null, string|int|Level $level = Logger::DEBUG, bool $bubble = true) + public function __construct(string $endpoint = 'http://127.0.0.1:9200', string $index = 'monolog', HttpClientInterface $client = null, string|int|Level $level = Logger::DEBUG, bool $bubble = true, string $elasticsearchVersion = '1.0.0') { if (!interface_exists(HttpClientInterface::class)) { throw new \LogicException(sprintf('The "%s" handler needs an HTTP client. Try running "composer require symfony/http-client".', __CLASS__)); @@ -71,6 +72,7 @@ public function __construct(string $endpoint = 'http://127.0.0.1:9200', string $ $this->index = $index; $this->client = $client ?: HttpClient::create(['timeout' => 1]); $this->responses = new \SplObjectStorage(); + $this->elasticsearchVersion = $elasticsearchVersion; } private function doHandle(array|LogRecord $record): bool @@ -108,18 +110,28 @@ private function sendToElasticsearch(array $records) { $formatter = $this->getFormatter(); + if (version_compare($this->elasticsearchVersion, '7', '>=')) { + $headers = json_encode([ + 'index' => [ + '_index' => $this->index, + ], + ]); + } else { + $headers = json_encode([ + 'index' => [ + '_index' => $this->index, + '_type' => '_doc', + ], + ]); + } + $body = ''; foreach ($records as $record) { foreach ($this->processors as $processor) { $record = $processor($record); } - $body .= json_encode([ - 'index' => [ - '_index' => $this->index, - '_type' => '_doc', - ], - ]); + $body .= $headers; $body .= "\n"; $body .= $formatter->format($record); $body .= "\n"; diff --git a/src/Symfony/Bridge/Monolog/Tests/Handler/ElasticsearchLogstashHandlerTest.php b/src/Symfony/Bridge/Monolog/Tests/Handler/ElasticsearchLogstashHandlerTest.php index 1074ca47d32ee..3e8dde6d4bbda 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Handler/ElasticsearchLogstashHandlerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Handler/ElasticsearchLogstashHandlerTest.php @@ -58,6 +58,42 @@ public function testHandle() $this->assertSame(1, $callCount); } + public function testHandleWithElasticsearch8() + { + $callCount = 0; + $responseFactory = function ($method, $url, $options) use (&$callCount) { + $body = <<assertSame('POST', $method); + $this->assertSame('http://es:9200/_bulk', $url); + $this->assertSame($body, $options['body']); + $this->assertSame('Content-Type: application/json', $options['normalized_headers']['content-type'][0]); + ++$callCount; + + return new MockResponse(); + }; + + $handler = new ElasticsearchLogstashHandler('http://es:9200', 'log', new MockHttpClient($responseFactory), Logger::DEBUG, true, '8.0.0'); + $handler->setFormatter($this->getDefaultFormatter()); + + $record = RecordFactory::create(Logger::INFO, 'My info message', 'app', datetime: new \DateTimeImmutable('2020-01-01T00:00:00+01:00')); + + $handler->handle($record); + + $this->assertSame(1, $callCount); + } + public function testHandleBatch() { $callCount = 0; diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php index 04d24883a9920..a432c31183669 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Configuration.php @@ -208,6 +208,10 @@ public function isIgnoredDeprecation(Deprecation $deprecation): bool */ public function isBaselineDeprecation(Deprecation $deprecation) { + if ($deprecation->isLegacy()) { + return false; + } + if ($deprecation->originatesFromAnObject()) { $location = $deprecation->originatingClass().'::'.$deprecation->originatingMethod(); } else { diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline.phpt index 533912c106cbd..83d448ea8ca7b 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline.phpt @@ -78,3 +78,4 @@ print "Cannot test baselineFile contents because it is generated in a shutdown f ?> --EXPECT-- Cannot test baselineFile contents because it is generated in a shutdown function registered by another shutdown function. +Legacy deprecation notices (1) diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline2.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline2.phpt index f520912694a1e..925d5c2384901 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline2.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline2.phpt @@ -66,6 +66,8 @@ $foo->testLegacyFoo(); $foo->testNonLegacyBar(); ?> --EXPECTF-- +Legacy deprecation notices (1) + Other deprecation notices (2) 1x: root deprecation diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline3.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline3.phpt index 28d1a74ffd427..d814c02b555b3 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline3.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/baseline3.phpt @@ -69,7 +69,7 @@ $foo->testLegacyFoo(); $foo->testNonLegacyBar(); ?> --EXPECTF-- -Legacy deprecation notices (1) +Legacy deprecation notices (2) Other deprecation notices (2) diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/generate_baseline.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/generate_baseline.phpt index 112a02b4c41a0..5b80791a15112 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/generate_baseline.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/generate_baseline.phpt @@ -62,3 +62,4 @@ print "Cannot test baselineFile contents because it is generated in a shutdown f ?> --EXPECT-- Cannot test baselineFile contents because it is generated in a shutdown function registered by another shutdown function. +Legacy deprecation notices (1) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index f3484ca7715d1..c041a51f9c300 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -191,7 +191,7 @@ private function createFieldTranslation(?string $value, array $parameters, strin * * @see ChoiceView::isSelected() */ -function twig_is_selected_choice(ChoiceView $choice, string|array $selectedValue): bool +function twig_is_selected_choice(ChoiceView $choice, string|array|null $selectedValue): bool { if (\is_array($selectedValue)) { return \in_array($choice->value, $selectedValue, true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php index 9afb6326179fd..175dc2e23d0da 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/html_sanitizer.php @@ -18,7 +18,7 @@ return static function (ContainerConfigurator $container) { $container->services() ->set('html_sanitizer.config.default', HtmlSanitizerConfig::class) - ->call('allowSafeElements') + ->call('allowSafeElements', [], true) ->set('html_sanitizer.sanitizer.default', HtmlSanitizer::class) ->args([service('html_sanitizer.config.default')]) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php index 5655c05a26e35..c960f12d3954a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php @@ -98,7 +98,7 @@ ->set('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class) ->args([null, null]) - ->tag('serializer.normalizer', ['priority' => -900]) + ->tag('serializer.normalizer', ['priority' => -950]) ->set('serializer.normalizer.problem', ProblemNormalizer::class) ->args([param('kernel.debug')]) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer.php index 2c8e2eb165071..2d117e8380a45 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer.php @@ -4,7 +4,7 @@ 'http_method_override' => false, 'html_sanitizer' => [ 'sanitizers' => [ - 'default' => [ + 'custom' => [ 'allow_safe_elements' => true, 'allow_static_elements' => true, 'allow_elements' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer_default_config.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer_default_config.php new file mode 100644 index 0000000000000..ae973a2db6b5c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/html_sanitizer_default_config.php @@ -0,0 +1,5 @@ +loadFromExtension('framework', [ + 'http_method_override' => false, + 'html_sanitizer' => null]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/html_sanitizer.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/html_sanitizer.xml index a974ec6cab418..771652c8d1a28 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/html_sanitizer.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/html_sanitizer.xml @@ -7,7 +7,7 @@ - + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer.yml index 414fcfffcf5f1..007f4875b6f79 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer.yml @@ -2,7 +2,7 @@ framework: http_method_override: false html_sanitizer: sanitizers: - default: + custom: allow_safe_elements: true allow_static_elements: true allow_elements: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer_default_config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer_default_config.yml new file mode 100644 index 0000000000000..94fff31d66886 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/html_sanitizer_default_config.yml @@ -0,0 +1,3 @@ +framework: + http_method_override: false + html_sanitizer: ~ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index c932298ce2cdd..3347a16877b88 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1438,7 +1438,7 @@ public function testJsonSerializableNormalizerRegistered() $tag = $definition->getTag('serializer.normalizer'); $this->assertEquals(JsonSerializableNormalizer::class, $definition->getClass()); - $this->assertEquals(-900, $tag[0]['priority']); + $this->assertEquals(-950, $tag[0]['priority']); } public function testObjectNormalizerRegistered() @@ -2050,16 +2050,14 @@ public function testHtmlSanitizer() $container = $this->createContainerFromFile('html_sanitizer'); // html_sanitizer service - $this->assertTrue($container->hasAlias('html_sanitizer'), '->registerHtmlSanitizerConfiguration() loads html_sanitizer.php'); - $this->assertSame('html_sanitizer.sanitizer.default', (string) $container->getAlias('html_sanitizer')); - $this->assertSame(HtmlSanitizer::class, $container->getDefinition('html_sanitizer.sanitizer.default')->getClass()); - $this->assertCount(1, $args = $container->getDefinition('html_sanitizer.sanitizer.default')->getArguments()); - $this->assertSame('html_sanitizer.config.default', (string) $args[0]); + $this->assertSame(HtmlSanitizer::class, $container->getDefinition('html_sanitizer.sanitizer.custom')->getClass()); + $this->assertCount(1, $args = $container->getDefinition('html_sanitizer.sanitizer.custom')->getArguments()); + $this->assertSame('html_sanitizer.config.custom', (string) $args[0]); // config - $this->assertTrue($container->hasDefinition('html_sanitizer.config.default'), '->registerHtmlSanitizerConfiguration() loads custom sanitizer'); - $this->assertSame(HtmlSanitizerConfig::class, $container->getDefinition('html_sanitizer.config.default')->getClass()); - $this->assertCount(23, $calls = $container->getDefinition('html_sanitizer.config.default')->getMethodCalls()); + $this->assertTrue($container->hasDefinition('html_sanitizer.config.custom'), '->registerHtmlSanitizerConfiguration() loads custom sanitizer'); + $this->assertSame(HtmlSanitizerConfig::class, $container->getDefinition('html_sanitizer.config.custom')->getClass()); + $this->assertCount(23, $calls = $container->getDefinition('html_sanitizer.config.custom')->getMethodCalls()); $this->assertSame( [ ['allowSafeElements', [], true], @@ -2103,6 +2101,30 @@ static function ($call) { // Named alias $this->assertSame('html_sanitizer.sanitizer.all.sanitizer', (string) $container->getAlias(HtmlSanitizerInterface::class.' $allSanitizer')); $this->assertFalse($container->hasAlias(HtmlSanitizerInterface::class.' $default')); + } + + public function testHtmlSanitizerDefaultConfig() + { + $container = $this->createContainerFromFile('html_sanitizer_default_config'); + + // html_sanitizer service + $this->assertTrue($container->hasAlias('html_sanitizer'), '->registerHtmlSanitizerConfiguration() loads default_config'); + $this->assertSame('html_sanitizer.sanitizer.default', (string) $container->getAlias('html_sanitizer')); + $this->assertSame(HtmlSanitizer::class, $container->getDefinition('html_sanitizer.sanitizer.default')->getClass()); + $this->assertCount(1, $args = $container->getDefinition('html_sanitizer.sanitizer.default')->getArguments()); + $this->assertSame('html_sanitizer.config.default', (string) $args[0]); + + // config + $this->assertTrue($container->hasDefinition('html_sanitizer.config.default'), '->registerHtmlSanitizerConfiguration() loads custom sanitizer'); + $this->assertSame(HtmlSanitizerConfig::class, $container->getDefinition('html_sanitizer.config.default')->getClass()); + $this->assertCount(1, $calls = $container->getDefinition('html_sanitizer.config.default')->getMethodCalls()); + $this->assertSame( + ['allowSafeElements', [], true], + $calls[0] + ); + + // Named alias + $this->assertFalse($container->hasAlias(HtmlSanitizerInterface::class.' $default')); // Default alias $this->assertSame('html_sanitizer', (string) $container->getAlias(HtmlSanitizerInterface::class)); diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index 9b425459b21ba..a5aefe35b9baa 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -19,7 +19,7 @@ "php": ">=8.1", "symfony/config": "^5.4|^6.0", "symfony/framework-bundle": "^5.4|^6.0", - "symfony/http-kernel": "^5.4|^6.0", + "symfony/http-kernel": "^6.1", "symfony/routing": "^5.4|^6.0", "symfony/twig-bundle": "^5.4|^6.0", "twig/twig": "^2.13|^3.0.4" diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index f687074011dec..871f17da555e9 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -85,7 +85,10 @@ public function get(string $key, callable $callback, float $beta = null, array & // ArrayAdapter works in memory, we don't care about stampede protection if (\INF === $beta || !$item->isHit()) { $save = true; - $this->save($item->set($callback($item, $save))); + $item->set($callback($item, $save)); + if ($save) { + $this->save($item); + } } return $item->get(); diff --git a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php index bd840367c37bf..50f5db0e93f86 100644 --- a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php @@ -93,9 +93,17 @@ static function ($sourceItem, $item, $defaultLifetime, $sourceMetadata = null) { */ public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed { + $doSave = true; + $callback = static function (CacheItem $item, bool &$save) use ($callback, &$doSave) { + $value = $callback($item, $save); + $doSave = $save; + + return $value; + }; + $lastItem = null; $i = 0; - $wrap = function (CacheItem $item = null) use ($key, $callback, $beta, &$wrap, &$i, &$lastItem, &$metadata) { + $wrap = function (CacheItem $item = null, bool &$save = true) use ($key, $callback, $beta, &$wrap, &$i, &$doSave, &$lastItem, &$metadata) { $adapter = $this->adapters[$i]; if (isset($this->adapters[++$i])) { $callback = $wrap; @@ -109,6 +117,7 @@ public function get(string $key, callable $callback, float $beta = null, array & if (null !== $item) { (self::$syncItem)($lastItem ??= $item, $item, $this->defaultLifetime, $metadata); } + $save = $doSave; return $value; }; diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php index ab0f7da134f90..a2c365162d5ef 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php @@ -108,6 +108,31 @@ public function testRecursiveGet() $this->assertSame(1, $cache->get('k2', function () { return 2; })); } + public function testDontSaveWhenAskedNotTo() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + + $cache = $this->createCachePool(0, __FUNCTION__); + + $v1 = $cache->get('some-key', function($item, &$save){ + $save = false; + return 1; + }); + $this->assertSame($v1, 1); + + $v2 = $cache->get('some-key', function(){ + return 2; + }); + $this->assertSame($v2, 2, 'First value was cached and should not have been'); + + $v3 = $cache->get('some-key', function(){ + $this->fail('Value should have come from cache'); + }); + $this->assertSame($v3, 2); + } + public function testGetMetadata() { if (isset($this->skippedTests[__FUNCTION__])) { diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php index bf1ca393cecc7..83e230e8c22a6 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php @@ -25,6 +25,7 @@ class PhpArrayAdapterTest extends AdapterTestCase { protected $skippedTests = [ 'testGet' => 'PhpArrayAdapter is read-only.', + 'testDontSaveWhenAskedNotTo' => 'PhpArrayAdapter is read-only.', 'testRecursiveGet' => 'PhpArrayAdapter is read-only.', 'testBasicUsage' => 'PhpArrayAdapter is read-only.', 'testBasicUsageWithLongKey' => 'PhpArrayAdapter is read-only.', diff --git a/src/Symfony/Component/Console/Tester/ApplicationTester.php b/src/Symfony/Component/Console/Tester/ApplicationTester.php index ffa21cba4de66..58aee54d616c6 100644 --- a/src/Symfony/Component/Console/Tester/ApplicationTester.php +++ b/src/Symfony/Component/Console/Tester/ApplicationTester.php @@ -49,17 +49,37 @@ public function __construct(Application $application) */ public function run(array $input, array $options = []): int { - $this->input = new ArrayInput($input); - if (isset($options['interactive'])) { - $this->input->setInteractive($options['interactive']); - } + $prevShellVerbosity = getenv('SHELL_VERBOSITY'); - if ($this->inputs) { - $this->input->setStream(self::createStream($this->inputs)); - } + try { + $this->input = new ArrayInput($input); + if (isset($options['interactive'])) { + $this->input->setInteractive($options['interactive']); + } - $this->initOutput($options); + if ($this->inputs) { + $this->input->setStream(self::createStream($this->inputs)); + } - return $this->statusCode = $this->application->run($this->input, $this->output); + $this->initOutput($options); + + return $this->statusCode = $this->application->run($this->input, $this->output); + } finally { + // SHELL_VERBOSITY is set by Application::configureIO so we need to unset/reset it + // to its previous value to avoid one test's verbosity to spread to the following tests + if (false === $prevShellVerbosity) { + if (\function_exists('putenv')) { + @putenv('SHELL_VERBOSITY'); + } + unset($_ENV['SHELL_VERBOSITY']); + unset($_SERVER['SHELL_VERBOSITY']); + } else { + if (\function_exists('putenv')) { + @putenv('SHELL_VERBOSITY='.$prevShellVerbosity); + } + $_ENV['SHELL_VERBOSITY'] = $prevShellVerbosity; + $_SERVER['SHELL_VERBOSITY'] = $prevShellVerbosity; + } + } } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index aaef9930692db..1ce97fc4d8990 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -814,7 +814,7 @@ public function testLazyArgumentProvideGenerator() switch (++$i) { case 0: $this->assertEquals('k1', $k); - $this->assertInstanceOf(\stdCLass::class, $v); + $this->assertInstanceOf(\stdClass::class, $v); break; case 1: $this->assertEquals('k2', $k); diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php index 6132a80b87cb2..9e7ec6e7825d0 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php @@ -180,7 +180,8 @@ public function testEvaluateMatchesWithInvalidRegexp() { $node = new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('this is not a regexp')); - $this->expectExceptionObject(new SyntaxError('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric or backslash')); + $this->expectException(SyntaxError::class); + $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric'); $node->evaluate([], []); } @@ -188,7 +189,8 @@ public function testEvaluateMatchesWithInvalidRegexpAsExpression() { $node = new BinaryNode('matches', new ConstantNode('abc'), new NameNode('regexp')); - $this->expectExceptionObject(new SyntaxError('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric or backslash')); + $this->expectException(SyntaxError::class); + $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric'); $node->evaluate([], ['regexp' => 'this is not a regexp']); } @@ -196,7 +198,8 @@ public function testCompileMatchesWithInvalidRegexp() { $node = new BinaryNode('matches', new ConstantNode('abc'), new ConstantNode('this is not a regexp')); - $this->expectExceptionObject(new SyntaxError('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric or backslash')); + $this->expectException(SyntaxError::class); + $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric'); $compiler = new Compiler([]); $node->compile($compiler); } @@ -205,7 +208,8 @@ public function testCompileMatchesWithInvalidRegexpAsExpression() { $node = new BinaryNode('matches', new ConstantNode('abc'), new NameNode('regexp')); - $this->expectExceptionObject(new SyntaxError('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric or backslash')); + $this->expectException(SyntaxError::class); + $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric'); $compiler = new Compiler([]); $node->compile($compiler); eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';'); diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index e78822dca4c2f..0040f3c139498 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -193,11 +193,8 @@ private static function getMaxFilesize(): int|float switch (substr($iniMax, -1)) { case 't': $max *= 1024; - // no break case 'g': $max *= 1024; - // no break case 'm': $max *= 1024; - // no break case 'k': $max *= 1024; } diff --git a/src/Symfony/Component/Form/Util/ServerParams.php b/src/Symfony/Component/Form/Util/ServerParams.php index 0038cb83ccf9c..c9dffab27076f 100644 --- a/src/Symfony/Component/Form/Util/ServerParams.php +++ b/src/Symfony/Component/Form/Util/ServerParams.php @@ -58,11 +58,8 @@ public function getPostMaxSize(): int|float|null switch (substr($iniMax, -1)) { case 't': $max *= 1024; - // no break case 'g': $max *= 1024; - // no break case 'm': $max *= 1024; - // no break case 'k': $max *= 1024; } diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index 9aff84dbca73b..96c37a5cf6923 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -301,7 +301,7 @@ public function request(string $method, string $url, array $options = []): Respo } } - return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number']); + return $pushedResponse ?? new CurlResponse($this->multi, $ch, $options, $this->logger, $method, self::createRedirectResolver($options, $host, $port), CurlClientState::$curlVersion['version_number'], $url); } /** diff --git a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php index dc4b6762b87a7..7265bab13bb01 100644 --- a/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php +++ b/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php @@ -178,8 +178,7 @@ private function getCurlCommand(array $trace): ?string return null; } - $debug = explode("\n", $trace['info']['debug']); - $url = self::mergeQueryString($trace['url'], $trace['options']['query'] ?? [], true); + $url = $trace['info']['original_url'] ?? $trace['info']['url'] ?? $trace['url']; $command = ['curl', '--compressed']; if (isset($trace['options']['resolve'])) { @@ -194,12 +193,12 @@ private function getCurlCommand(array $trace): ?string $dataArg = []; if ($json = $trace['options']['json'] ?? null) { - $dataArg[] = '--data '.escapeshellarg(json_encode($json, \JSON_PRETTY_PRINT)); + $dataArg[] = '--data '.escapeshellarg(self::jsonEncode($json)); } elseif ($body = $trace['options']['body'] ?? null) { if (\is_string($body)) { try { $dataArg[] = '--data '.escapeshellarg($body); - } catch (\ValueError $e) { + } catch (\ValueError) { return null; } } elseif (\is_array($body)) { @@ -214,7 +213,7 @@ private function getCurlCommand(array $trace): ?string $dataArg = empty($dataArg) ? null : implode(' ', $dataArg); - foreach ($debug as $line) { + foreach (explode("\n", $trace['info']['debug']) as $line) { $line = substr($line, 0, -1); if (str_starts_with('< ', $line)) { diff --git a/src/Symfony/Component/HttpClient/Response/AmpResponse.php b/src/Symfony/Component/HttpClient/Response/AmpResponse.php index f5d0095ec97c6..f107ccfa6cf65 100644 --- a/src/Symfony/Component/HttpClient/Response/AmpResponse.php +++ b/src/Symfony/Component/HttpClient/Response/AmpResponse.php @@ -80,6 +80,7 @@ public function __construct(AmpClientState $multi, Request $request, array $opti $info['http_method'] = $request->getMethod(); $info['start_time'] = null; $info['redirect_url'] = null; + $info['original_url'] = $info['url']; $info['redirect_time'] = 0.0; $info['redirect_count'] = 0; $info['size_upload'] = 0.0; diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index 9a8abca522025..233198f3d78fd 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -43,7 +43,7 @@ final class CurlResponse implements ResponseInterface, StreamableInterface /** * @internal */ - public function __construct(CurlClientState $multi, \CurlHandle|string $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null) + public function __construct(CurlClientState $multi, \CurlHandle|string $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null, string $originalUrl = null) { $this->multi = $multi; @@ -69,6 +69,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra $this->info['user_data'] = $options['user_data'] ?? null; $this->info['max_duration'] = $options['max_duration'] ?? null; $this->info['start_time'] = $this->info['start_time'] ?? microtime(true); + $this->info['original_url'] = $originalUrl ?? $this->info['url'] ?? curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL); $info = &$this->info; $headers = &$this->headers; $debugBuffer = $this->debugBuffer; diff --git a/src/Symfony/Component/HttpClient/Response/MockResponse.php b/src/Symfony/Component/HttpClient/Response/MockResponse.php index fe89cd18edbb5..044734a3b8d87 100644 --- a/src/Symfony/Component/HttpClient/Response/MockResponse.php +++ b/src/Symfony/Component/HttpClient/Response/MockResponse.php @@ -142,6 +142,7 @@ public static function fromRequest(string $method, string $url, array $options, $response->info['user_data'] = $options['user_data'] ?? null; $response->info['max_duration'] = $options['max_duration'] ?? null; $response->info['url'] = $url; + $response->info['original_url'] = $url; if ($mock instanceof self) { $mock->requestOptions = $response->requestOptions; diff --git a/src/Symfony/Component/HttpClient/Response/NativeResponse.php b/src/Symfony/Component/HttpClient/Response/NativeResponse.php index 077d8f9a8ddcc..ab0cf095908f7 100644 --- a/src/Symfony/Component/HttpClient/Response/NativeResponse.php +++ b/src/Symfony/Component/HttpClient/Response/NativeResponse.php @@ -66,6 +66,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr // Temporary resource to dechunk the response stream $this->buffer = fopen('php://temp', 'w+'); + $info['original_url'] = implode('', $info['url']); $info['user_data'] = $options['user_data']; $info['max_duration'] = $options['max_duration']; ++$multi->responseCount; diff --git a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php index 863c91d3d68db..18b08473aa2f2 100755 --- a/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php +++ b/src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php @@ -194,6 +194,22 @@ public function provideCurlRequests(): iterable --url %1$shttp://localhost:8057/json%1$s \\ --header %1$sAccept: */*%1$s \\ --header %1$sAccept-Encoding: gzip%1$s \\ + --header %1$sUser-Agent: Symfony HttpClient/Native%1$s', + ]; + yield 'GET with base uri' => [ + [ + 'method' => 'GET', + 'url' => '1', + 'options' => [ + 'base_uri' => 'http://localhost:8057/json/', + ], + ], + 'curl \\ + --compressed \\ + --request GET \\ + --url %1$shttp://localhost:8057/json/1%1$s \\ + --header %1$sAccept: */*%1$s \\ + --header %1$sAccept-Encoding: gzip%1$s \\ --header %1$sUser-Agent: Symfony HttpClient/Native%1$s', ]; yield 'GET with resolve' => [ @@ -307,6 +323,8 @@ public function __toString(): string 'json' => [ 'foo' => [ 'bar' => 'baz', + 'qux' => [1.10, 1.0], + 'fred' => ['',"'bar'",'"baz"','&blong&'], ], ], ], @@ -317,14 +335,10 @@ public function __toString(): string --url %1$shttp://localhost:8057/json%1$s \\ --header %1$sContent-Type: application/json%1$s \\ --header %1$sAccept: */*%1$s \\ - --header %1$sContent-Length: 21%1$s \\ + --header %1$sContent-Length: 120%1$s \\ --header %1$sAccept-Encoding: gzip%1$s \\ --header %1$sUser-Agent: Symfony HttpClient/Native%1$s \\ - --data %1$s{ - "foo": { - "bar": "baz" - } -}%1$s', + --data %1$s{"foo":{"bar":"baz","qux":[1.1,1.0],"fred":["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026"]}}%1$s', ]; } } diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 11dad4a9a32ac..fa31901bd3a44 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -234,11 +234,8 @@ private static function parseFilesize(string $size): int|float switch (substr($size, -1)) { case 't': $max *= 1024; - // no break case 'g': $max *= 1024; - // no break case 'm': $max *= 1024; - // no break case 'k': $max *= 1024; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 50668bb136b30..5a0bca5d40dcb 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -136,7 +136,7 @@ public function start(): bool } $sessionId = $_COOKIE[session_name()] ?? null; - if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) { + if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) { // the session ID in the header is invalid, create a new one session_id(session_create_id()); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php index a771d2e010095..852a921262814 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php @@ -284,12 +284,31 @@ public function testGetBagsOnceSessionStartedIsIgnored() $this->assertEquals($storage->getBag('flashes'), $bag); } - public function testRegenerateInvalidSessionId() + public function testRegenerateInvalidSessionIdForNativeFileSessionHandler() { $_COOKIE[session_name()] = '&~['; - $started = (new NativeSessionStorage())->start(); + session_id('&~['); + $storage = new NativeSessionStorage([], new NativeFileSessionHandler()); + $started = $storage->start(); $this->assertTrue($started); $this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id()); + $storage->save(); + + $_COOKIE[session_name()] = '&~['; + session_id('&~['); + $storage = new NativeSessionStorage([], new SessionHandlerProxy(new NativeFileSessionHandler())); + $started = $storage->start(); + + $this->assertTrue($started); + $this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id()); + $storage->save(); + + $_COOKIE[session_name()] = '&~['; + session_id('&~['); + $storage = new NativeSessionStorage([], new NullSessionHandler()); + $started = $storage->start(); + $this->assertTrue($started); + $this->assertSame('&~[', session_id()); } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php index 392fb82884555..b2b72e03721ad 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php @@ -94,11 +94,8 @@ private function convertToBytes(string $memoryLimit): int|float switch (substr($memoryLimit, -1)) { case 't': $max *= 1024; - // no break case 'g': $max *= 1024; - // no break case 'm': $max *= 1024; - // no break case 'k': $max *= 1024; } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php index fac19763c41f0..af90e9e265a34 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\TerminateEvent; @@ -96,8 +97,21 @@ public function onKernelResponse(ResponseEvent $event) return; } - if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) { - return; + $session = $request->hasPreviousSession() && $request->hasSession() ? $request->getSession() : null; + + if ($session instanceof Session) { + $usageIndexValue = $usageIndexReference = &$session->getUsageIndex(); + $usageIndexReference = \PHP_INT_MIN; + } + + try { + if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) { + return; + } + } finally { + if ($session instanceof Session) { + $usageIndexReference = $usageIndexValue; + } } $this->profiles[$request] = $profile; diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index dc3eeac35aaf2..45ff4a006c605 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -692,7 +692,7 @@ private function mayServeStaleWhileRevalidate(Response $entry): bool $timeout = $this->options['stale_while_revalidate']; } - return abs($entry->getTtl()) < $timeout; + return abs($entry->getTtl() ?? 0) < $timeout; } /** diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index ab882201ee929..44beb5ca270ae 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -78,11 +78,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.1.1'; - public const VERSION_ID = 60101; + public const VERSION = '6.1.2'; + public const VERSION_ID = 60102; public const MAJOR_VERSION = 6; public const MINOR_VERSION = 1; - public const RELEASE_VERSION = 1; + public const RELEASE_VERSION = 2; public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2023'; diff --git a/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php index 7b2eef63ef30c..e3d1be1c08b96 100644 --- a/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Tests/Transport/OhMySmtpApiTransportTest.php @@ -100,7 +100,7 @@ public function testSend() public function testSendThrowsForErrorResponse() { $client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface { - return new MockResponse(json_encode(['Message' => 'i\'m a teapot', 'ErrorCode' => 418]), [ + return new MockResponse(json_encode(['error' => 'i\'m a teapot']), [ 'http_code' => 418, 'response_headers' => [ 'content-type' => 'application/json', @@ -117,7 +117,31 @@ public function testSendThrowsForErrorResponse() ->text('Hello There!'); $this->expectException(HttpTransportException::class); - $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).'); + $this->expectExceptionMessage('Unable to send an email: {"error":"i\'m a teapot"}'); + $transport->send($mail); + } + + public function testSendThrowsForMultipleErrorResponses() + { + $client = new MockHttpClient(static function (string $method, string $url, array $options): ResponseInterface { + return new MockResponse(json_encode(['errors' => ["to" => "undefined field" ]]), [ + 'http_code' => 418, + 'response_headers' => [ + 'content-type' => 'application/json', + ], + ]); + }); + $transport = new OhMySmtpApiTransport('KEY', $client); + $transport->setPort(8984); + + $mail = new Email(); + $mail->subject('Hello!') + ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin')) + ->from(new Address('fabpot@symfony.com', 'Fabien')) + ->text('Hello There!'); + + $this->expectException(HttpTransportException::class); + $this->expectExceptionMessage('Unable to send an email: {"errors":{"to":"undefined field"}}'); $transport->send($mail); } diff --git a/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php b/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php index 9124b71dbe3ad..93f68645b0c5a 100644 --- a/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/OhMySmtp/Transport/OhMySmtpApiTransport.php @@ -67,7 +67,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e } if (200 !== $statusCode) { - throw new HttpTransportException('Unable to send an email: '.$result['Message'].sprintf(' (code %d).', $result['ErrorCode']), $response); + throw new HttpTransportException('Unable to send an email: '.$response->getContent(false), $response); } $sentMessage->setMessageId($result['id']); diff --git a/src/Symfony/Component/Mailer/EventListener/EnvelopeListener.php b/src/Symfony/Component/Mailer/EventListener/EnvelopeListener.php index a5516f4530153..d47a688ca9d25 100644 --- a/src/Symfony/Component/Mailer/EventListener/EnvelopeListener.php +++ b/src/Symfony/Component/Mailer/EventListener/EnvelopeListener.php @@ -51,7 +51,7 @@ public function onMessage(MessageEvent $event): void $message = $event->getMessage(); if ($message instanceof Message) { if (!$message->getHeaders()->has('Sender') && !$message->getHeaders()->has('From')) { - $message->getHeaders()->addMailboxHeader('Sender', $this->sender->getAddress()); + $message->getHeaders()->addMailboxHeader('Sender', $this->sender); } } } diff --git a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php index 1854a8a000150..0eb6e9070bb87 100644 --- a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php @@ -252,11 +252,8 @@ private function convertToBytes(string $memoryLimit): int switch (substr(rtrim($memoryLimit, 'b'), -1)) { case 't': $max *= 1024; - // no break case 'g': $max *= 1024; - // no break case 'm': $max *= 1024; - // no break case 'k': $max *= 1024; } diff --git a/src/Symfony/Component/Messenger/EventListener/ResetServicesListener.php b/src/Symfony/Component/Messenger/EventListener/ResetServicesListener.php index 091b170e596eb..12bd1db4cca83 100644 --- a/src/Symfony/Component/Messenger/EventListener/ResetServicesListener.php +++ b/src/Symfony/Component/Messenger/EventListener/ResetServicesListener.php @@ -14,6 +14,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Component\Messenger\Event\WorkerRunningEvent; +use Symfony\Component\Messenger\Event\WorkerStoppedEvent; /** * @author Grégoire Pineau @@ -34,10 +35,16 @@ public function resetServices(WorkerRunningEvent $event): void } } + public function resetServicesAtStop(WorkerStoppedEvent $event): void + { + $this->servicesResetter->reset(); + } + public static function getSubscribedEvents(): array { return [ WorkerRunningEvent::class => ['resetServices', -1024], + WorkerStoppedEvent::class => ['resetServicesAtStop', -1024], ]; } } diff --git a/src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php b/src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php index 823caed40b023..31b418a2ecce4 100644 --- a/src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php +++ b/src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php @@ -56,7 +56,6 @@ public function onMessageFailed(WorkerMessageFailedEvent $event) $message = $envelope->getMessage(); $context = [ - 'message' => $message, 'class' => \get_class($message), ]; diff --git a/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php b/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php index b6499b8f9ddc5..537c2845826de 100644 --- a/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php @@ -53,7 +53,6 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope $message = $envelope->getMessage(); $context = [ - 'message' => $message, 'class' => \get_class($message), ]; diff --git a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php index e2c1bd571c5b3..016c2e9f1c5f3 100644 --- a/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php +++ b/src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php @@ -44,7 +44,6 @@ public function __construct(SendersLocatorInterface $sendersLocator, EventDispat public function handle(Envelope $envelope, StackInterface $stack): Envelope { $context = [ - 'message' => $envelope->getMessage(), 'class' => \get_class($envelope->getMessage()), ]; diff --git a/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php index 8a6f5a7d608cf..1bcfeb04a987a 100644 --- a/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php +++ b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php @@ -26,6 +26,7 @@ use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\RoutableMessageBus; use Symfony\Component\Messenger\Stamp\BusNameStamp; +use Symfony\Component\Messenger\Tests\ResettableDummyReceiver; use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; class ConsumeMessagesCommandTest extends TestCase @@ -116,15 +117,11 @@ public function testRunWithResetServicesOption(bool $shouldReset) { $envelope = new Envelope(new \stdClass()); - $receiver = $this->createMock(ReceiverInterface::class); - $receiver - ->expects($this->exactly(3)) - ->method('get') - ->willReturnOnConsecutiveCalls( - [$envelope], - [/* idle */], - [$envelope, $envelope] - ); + $receiver = new ResettableDummyReceiver([ + [$envelope], + [/* idle */], + [$envelope, $envelope], + ]); $msgCount = 3; $receiverLocator = $this->createMock(ContainerInterface::class); @@ -134,8 +131,7 @@ public function testRunWithResetServicesOption(bool $shouldReset) $bus = $this->createMock(RoutableMessageBus::class); $bus->expects($this->exactly($msgCount))->method('dispatch'); - $servicesResetter = $this->createMock(ServicesResetter::class); - $servicesResetter->expects($this->exactly($shouldReset ? $msgCount : 0))->method('reset'); + $servicesResetter = new ServicesResetter(new \ArrayIterator([$receiver]), ['reset']); $command = new ConsumeMessagesCommand($bus, $receiverLocator, new EventDispatcher(), null, [], new ResetServicesListener($servicesResetter)); @@ -148,6 +144,7 @@ public function testRunWithResetServicesOption(bool $shouldReset) '--limit' => $msgCount, ], $shouldReset ? [] : ['--no-reset' => null])); + $this->assertEquals($shouldReset, $receiver->hasBeenReset(), '$receiver->reset() should have been called'); $tester->assertCommandIsSuccessful(); $this->assertStringContainsString('[OK] Consuming messages from transports "dummy-receiver"', $tester->getDisplay()); } diff --git a/src/Symfony/Component/Messenger/Tests/EventListener/ResetServicesListenerTest.php b/src/Symfony/Component/Messenger/Tests/EventListener/ResetServicesListenerTest.php index ce8f771a0952f..12f86ec6c83cb 100644 --- a/src/Symfony/Component/Messenger/Tests/EventListener/ResetServicesListenerTest.php +++ b/src/Symfony/Component/Messenger/Tests/EventListener/ResetServicesListenerTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Component\Messenger\Event\WorkerRunningEvent; +use Symfony\Component\Messenger\Event\WorkerStoppedEvent; use Symfony\Component\Messenger\EventListener\ResetServicesListener; use Symfony\Component\Messenger\Worker; @@ -38,4 +39,15 @@ public function testResetServices(bool $shouldReset) $resetListener = new ResetServicesListener($servicesResetter); $resetListener->resetServices($event); } + + public function testResetServicesAtStop() + { + $servicesResetter = $this->createMock(ServicesResetter::class); + $servicesResetter->expects($this->once())->method('reset'); + + $event = new WorkerStoppedEvent($this->createMock(Worker::class)); + + $resetListener = new ResetServicesListener($servicesResetter); + $resetListener->resetServicesAtStop($event); + } } diff --git a/src/Symfony/Component/Messenger/Tests/WorkerTest.php b/src/Symfony/Component/Messenger/Tests/WorkerTest.php index a3b1bfa74a2b9..747c6ed855d79 100644 --- a/src/Symfony/Component/Messenger/Tests/WorkerTest.php +++ b/src/Symfony/Component/Messenger/Tests/WorkerTest.php @@ -15,6 +15,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; @@ -22,6 +23,7 @@ use Symfony\Component\Messenger\Event\WorkerRunningEvent; use Symfony\Component\Messenger\Event\WorkerStartedEvent; use Symfony\Component\Messenger\Event\WorkerStoppedEvent; +use Symfony\Component\Messenger\EventListener\ResetServicesListener; use Symfony\Component\Messenger\EventListener\StopWorkerOnMessageLimitListener; use Symfony\Component\Messenger\Exception\RuntimeException; use Symfony\Component\Messenger\Handler\Acknowledger; @@ -118,15 +120,50 @@ public function testWorkerResetsConnectionIfReceiverIsResettable() { $resettableReceiver = new ResettableDummyReceiver([]); - $bus = $this->createMock(MessageBusInterface::class); $dispatcher = new EventDispatcher(); + $dispatcher->addSubscriber(new ResetServicesListener(new ServicesResetter(new \ArrayIterator([$resettableReceiver]), ['reset']))); + $bus = $this->createMock(MessageBusInterface::class); $worker = new Worker([$resettableReceiver], $bus, $dispatcher); $worker->stop(); $worker->run(); $this->assertTrue($resettableReceiver->hasBeenReset()); } + public function testWorkerResetsTransportsIfResetServicesListenerIsCalled() + { + $envelope = new Envelope(new DummyMessage('Hello')); + $resettableReceiver = new ResettableDummyReceiver([[$envelope]]); + + $dispatcher = new EventDispatcher(); + $dispatcher->addSubscriber(new ResetServicesListener(new ServicesResetter(new \ArrayIterator([$resettableReceiver]), ['reset']))); + $dispatcher->addListener(WorkerRunningEvent::class, function (WorkerRunningEvent $event) { + $event->getWorker()->stop(); + }); + + $bus = $this->createMock(MessageBusInterface::class); + $worker = new Worker([$resettableReceiver], $bus, $dispatcher); + $worker->run(); + $this->assertTrue($resettableReceiver->hasBeenReset()); + } + + public function testWorkerDoesNotResetTransportsIfResetServicesListenerIsNotCalled() + { + $envelope = new Envelope(new DummyMessage('Hello')); + $resettableReceiver = new ResettableDummyReceiver([[$envelope]]); + + $bus = $this->createMock(MessageBusInterface::class); + + $dispatcher = new EventDispatcher(); + $dispatcher->addListener(WorkerRunningEvent::class, function (WorkerRunningEvent $event) { + $event->getWorker()->stop(); + }); + + $worker = new Worker([$resettableReceiver], $bus, $dispatcher); + $worker->run(); + $this->assertFalse($resettableReceiver->hasBeenReset()); + } + public function testWorkerDoesNotSendNullMessagesToTheBus() { $receiver = new DummyReceiver([ diff --git a/src/Symfony/Component/Messenger/Worker.php b/src/Symfony/Component/Messenger/Worker.php index 1395bc77a1ff7..334e878fb1645 100644 --- a/src/Symfony/Component/Messenger/Worker.php +++ b/src/Symfony/Component/Messenger/Worker.php @@ -29,7 +29,6 @@ use Symfony\Component\Messenger\Stamp\ReceivedStamp; use Symfony\Component\Messenger\Transport\Receiver\QueueReceiverInterface; use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; -use Symfony\Contracts\Service\ResetInterface; /** * @author Samuel Roze @@ -134,7 +133,6 @@ public function run(array $options = []): void $this->flush(true); $this->eventDispatcher?->dispatch(new WorkerStoppedEvent($this)); - $this->resetReceiverConnections(); } private function handleMessage(Envelope $envelope, string $transportName): void @@ -208,7 +206,6 @@ private function ack(): bool if (null !== $this->logger) { $message = $envelope->getMessage(); $context = [ - 'message' => $message, 'class' => \get_class($message), ]; $this->logger->info('{class} was handled successfully (acknowledging to transport).', $context); @@ -255,13 +252,4 @@ public function getMetadata(): WorkerMetadata { return $this->metadata; } - - private function resetReceiverConnections(): void - { - foreach ($this->receivers as $receiver) { - if ($receiver instanceof ResetInterface) { - $receiver->reset(); - } - } - } } diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php index 52a4a78f2537f..429f43202543d 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php @@ -99,6 +99,14 @@ public function getTypes(string $class, string $property, array $context = []): continue; } + if ( + $tagDocNode->value instanceof ParamTagValueNode + && null === $prefix + && $tagDocNode->value->parameterName !== '$'.$property + ) { + continue; + } + foreach ($this->phpStanTypeHelper->getTypes($tagDocNode->value, $nameScope) as $type) { switch ($type->getClassName()) { case 'self': @@ -239,10 +247,6 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra $phpDocNode = $this->phpDocParser->parse($tokens); $tokens->consumeTokenType(Lexer::TOKEN_END); - if (self::MUTATOR === $source && !$this->filterDocBlockParams($phpDocNode, $property)) { - return null; - } - return [$phpDocNode, $source, $reflectionProperty->class]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php similarity index 99% rename from src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php rename to src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php index 7565994ee0c8c..9b49e70e202a7 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTestDoc.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpStanExtractorTest.php @@ -467,6 +467,7 @@ public function php80TypesProvider() return [ [Php80Dummy::class, 'promotedAndMutated', [new Type(Type::BUILTIN_TYPE_STRING)]], [Php80Dummy::class, 'promoted', null], + [Php80Dummy::class, 'collection', [new Type(Type::BUILTIN_TYPE_ARRAY, collection: true, collectionValueType: new Type(Type::BUILTIN_TYPE_STRING))]], [Php80PromotedDummy::class, 'promoted', null], ]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php index e7ae2fc83bfec..dc985fea0b212 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php @@ -17,8 +17,9 @@ class Php80Dummy /** * @param string $promotedAndMutated + * @param array $collection */ - public function __construct(private mixed $promoted, private mixed $promotedAndMutated) + public function __construct(private mixed $promoted, private mixed $promotedAndMutated, private array $collection) { } diff --git a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php index b3263cbca5fc3..76878f9ff2916 100644 --- a/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php +++ b/src/Symfony/Component/Security/Core/Exception/AccountStatusException.php @@ -22,7 +22,7 @@ */ abstract class AccountStatusException extends AuthenticationException { - private UserInterface $user; + private ?UserInterface $user = null; /** * Get the user. diff --git a/src/Symfony/Component/Security/Http/RememberMe/PersistentRememberMeHandler.php b/src/Symfony/Component/Security/Http/RememberMe/PersistentRememberMeHandler.php index 5b7682734dbf2..e7243ac8b049d 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/PersistentRememberMeHandler.php +++ b/src/Symfony/Component/Security/Http/RememberMe/PersistentRememberMeHandler.php @@ -75,6 +75,7 @@ public function processRememberMe(RememberMeDetails $rememberMeDetails, UserInte if ($this->tokenVerifier) { $isTokenValid = $this->tokenVerifier->verifyToken($persistentToken, $tokenValue); + $tokenValue = $persistentToken->getTokenValue(); } else { $isTokenValid = hash_equals($persistentToken->getTokenValue(), $tokenValue); } diff --git a/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentRememberMeHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentRememberMeHandlerTest.php index 7448520497eaf..770a1c634abe6 100644 --- a/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentRememberMeHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/RememberMe/PersistentRememberMeHandlerTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; use Symfony\Component\Security\Core\Authentication\RememberMe\TokenProviderInterface; +use Symfony\Component\Security\Core\Authentication\RememberMe\TokenVerifierInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\CookieTheftException; use Symfony\Component\Security\Core\User\InMemoryUser; @@ -102,6 +103,42 @@ public function testConsumeRememberMeCookieValid() $this->assertSame(explode(':', $rememberParts[3])[0], explode(':', $cookieParts[3])[0]); // series } + public function testConsumeRememberMeCookieValidByValidatorWithoutUpdate() + { + $verifier = $this->createMock(TokenVerifierInterface::class); + $handler = new PersistentRememberMeHandler($this->tokenProvider, 'secret', $this->userProvider, $this->requestStack, [], null, $verifier); + + $persistentToken = new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('30 seconds')); + + $this->tokenProvider->expects($this->any()) + ->method('loadTokenBySeries') + ->with('series1') + ->willReturn($persistentToken) + ; + + $verifier->expects($this->any()) + ->method('verifyToken') + ->with($persistentToken, 'oldTokenValue') + ->willReturn(true) + ; + + $rememberMeDetails = new RememberMeDetails(InMemoryUser::class, 'wouter', 360, 'series1:oldTokenValue'); + $handler->consumeRememberMeCookie($rememberMeDetails); + + // assert that the cookie has been updated with a new base64 encoded token value + $this->assertTrue($this->request->attributes->has(ResponseListener::COOKIE_ATTR_NAME)); + + /** @var Cookie $cookie */ + $cookie = $this->request->attributes->get(ResponseListener::COOKIE_ATTR_NAME); + + $cookieParts = explode(':', base64_decode($cookie->getValue()), 4); + + $this->assertSame(InMemoryUser::class, $cookieParts[0]); // class + $this->assertSame(base64_encode('wouter'), $cookieParts[1]); // identifier + $this->assertSame('360', $cookieParts[2]); // expire + $this->assertSame('series1:tokenvalue', $cookieParts[3]); // value + } + public function testConsumeRememberMeCookieInvalidToken() { $this->expectException(CookieTheftException::class); diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index e32533858efc2..760191255e408 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -21,6 +21,7 @@ use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Exception\ExtraAttributesException; use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException; use Symfony\Component\Serializer\Exception\NotNormalizableValueException; use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface; use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; @@ -421,7 +422,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar } } - if (!empty($extraAttributes)) { + if ($extraAttributes) { throw new ExtraAttributesException($extraAttributes); } @@ -439,12 +440,16 @@ abstract protected function setAttributeValue(object $object, string $attribute, * @param Type[] $types * * @throws NotNormalizableValueException + * @throws ExtraAttributesException + * @throws MissingConstructorArgumentsException * @throws LogicException */ private function validateAndDenormalize(array $types, string $currentClass, string $attribute, mixed $data, ?string $format, array $context): mixed { $expectedTypes = []; $isUnionType = \count($types) > 1; + $extraAttributesException = null; + $missingConstructorArgumentException = null; foreach ($types as $type) { if (null === $data && $type->isNullable()) { return null; @@ -575,9 +580,29 @@ private function validateAndDenormalize(array $types, string $currentClass, stri if (!$isUnionType) { throw $e; } + } catch (ExtraAttributesException $e) { + if (!$isUnionType) { + throw $e; + } + + $extraAttributesException ??= $e; + } catch (MissingConstructorArgumentsException $e) { + if (!$isUnionType) { + throw $e; + } + + $missingConstructorArgumentException ??= $e; } } + if ($extraAttributesException) { + throw $extraAttributesException; + } + + if ($missingConstructorArgumentException) { + throw $missingConstructorArgumentException; + } + if ($context[self::DISABLE_TYPE_ENFORCEMENT] ?? $this->defaultContext[self::DISABLE_TYPE_ENFORCEMENT] ?? false) { return $data; } diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index f04c4fbbaf97f..a7a676f938c60 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Symfony\Component\Serializer\Encoder\JsonEncoder; +use Symfony\Component\Serializer\Exception\ExtraAttributesException; use Symfony\Component\Serializer\Exception\InvalidArgumentException; use Symfony\Component\Serializer\Exception\LogicException; use Symfony\Component\Serializer\Exception\NotNormalizableValueException; @@ -32,6 +33,7 @@ use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer; @@ -751,6 +753,41 @@ public function testUnionTypeDeserializable() $this->assertEquals(new DummyUnionType(), $actual, 'Union type denormalization third case failed.'); } + public function testUnionTypeDeserializableWithoutAllowedExtraAttributes() + { + $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $extractor = new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]); + $serializer = new Serializer( + [ + new ObjectNormalizer($classMetadataFactory, null, null, $extractor, new ClassDiscriminatorFromClassMetadata($classMetadataFactory)), + ], + ['json' => new JsonEncoder()] + ); + + $actual = $serializer->deserialize('{ "v": { "a": 0 }}', DummyUnionWithAAndCAndB::class, 'json', [ + AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, + ]); + + $this->assertEquals(new DummyUnionWithAAndCAndB(new DummyATypeForUnion()), $actual); + + $actual = $serializer->deserialize('{ "v": { "b": 1 }}', DummyUnionWithAAndCAndB::class, 'json', [ + AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, + ]); + + $this->assertEquals(new DummyUnionWithAAndCAndB(new DummyBTypeForUnion()), $actual); + + $actual = $serializer->deserialize('{ "v": { "c": 3 }}', DummyUnionWithAAndCAndB::class, 'json', [ + AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, + ]); + + $this->assertEquals(new DummyUnionWithAAndCAndB(new DummyCTypeForUnion(3)), $actual); + + $this->expectException(ExtraAttributesException::class); + $serializer->deserialize('{ "v": { "b": 1, "d": "i am not allowed" }}', DummyUnionWithAAndCAndB::class, 'json', [ + AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false, + ]); + } + /** * @requires PHP 8.2 */ @@ -1215,6 +1252,40 @@ public function setChanged($changed): static } } +class DummyATypeForUnion +{ + public $a = 0; +} + +class DummyBTypeForUnion +{ + public $b = 1; +} + +class DummyCTypeForUnion +{ + public $c = 2; + + public function __construct($c) + { + $this->c = $c; + } +} + +class DummyUnionWithAAndCAndB +{ + /** @var DummyATypeForUnion|DummyCTypeForUnion|DummyBTypeForUnion */ + public $v; + + /** + * @param DummyATypeForUnion|DummyCTypeForUnion|DummyBTypeForUnion $v + */ + public function __construct($v) + { + $this->v = $v; + } +} + class Baz { public $list; diff --git a/src/Symfony/Component/String/Inflector/FrenchInflector.php b/src/Symfony/Component/String/Inflector/FrenchInflector.php index 42f6125aae663..f58f7c0c0e234 100644 --- a/src/Symfony/Component/String/Inflector/FrenchInflector.php +++ b/src/Symfony/Component/String/Inflector/FrenchInflector.php @@ -108,7 +108,7 @@ final class FrenchInflector implements InflectorInterface * A list of words which should not be inflected. * This list is only used by singularize. */ - private const UNINFLECTED = '/^(abcès|accès|abus|albatros|anchois|anglais|autobus|bois|brebis|carquois|cas|chas|colis|concours|corps|cours|cyprès|décès|devis|discours|dos|embarras|engrais|entrelacs|excès|fils|fois|gâchis|gars|glas|héros|intrus|jars|jus|kermès|lacis|legs|lilas|marais|mars|matelas|mépris|mets|mois|mors|obus|os|palais|paradis|parcours|pardessus|pays|plusieurs|poids|pois|pouls|printemps|processus|progrès|puits|pus|rabais|radis|recors|recours|refus|relais|remords|remous|rictus|rhinocéros|repas|rubis|sas|secours|sens|souris|succès|talus|tapis|tas|taudis|temps|tiers|univers|velours|verglas|vernis|virus)$/i'; + private const UNINFLECTED = '/^(abcès|accès|abus|albatros|anchois|anglais|autobus|bois|brebis|carquois|cas|chas|colis|concours|corps|cours|cyprès|décès|devis|discours|dos|embarras|engrais|entrelacs|excès|fils|fois|gâchis|gars|glas|héros|intrus|jars|jus|kermès|lacis|legs|lilas|marais|mars|matelas|mépris|mets|mois|mors|obus|os|palais|paradis|parcours|pardessus|pays|plusieurs|poids|pois|pouls|printemps|processus|progrès|puits|pus|rabais|radis|recors|recours|refus|relais|remords|remous|rictus|rhinocéros|repas|rubis|sans|sas|secours|sens|souris|succès|talus|tapis|tas|taudis|temps|tiers|univers|velours|verglas|vernis|virus)$/i'; /** * {@inheritdoc} diff --git a/src/Symfony/Component/String/Tests/Inflector/FrenchInflectorTest.php b/src/Symfony/Component/String/Tests/Inflector/FrenchInflectorTest.php index ff4deb4eac9aa..9122281c27c84 100644 --- a/src/Symfony/Component/String/Tests/Inflector/FrenchInflectorTest.php +++ b/src/Symfony/Component/String/Tests/Inflector/FrenchInflectorTest.php @@ -31,6 +31,7 @@ public function pluralizeProvider() ['héros', 'héros'], ['nez', 'nez'], ['rictus', 'rictus'], + ['sans', 'sans'], ['souris', 'souris'], ['tas', 'tas'], ['toux', 'toux'], diff --git a/src/Symfony/Component/Yaml/Tests/DumperTest.php b/src/Symfony/Component/Yaml/Tests/DumperTest.php index 0e3b16af91ca2..693db4ee0a684 100644 --- a/src/Symfony/Component/Yaml/Tests/DumperTest.php +++ b/src/Symfony/Component/Yaml/Tests/DumperTest.php @@ -28,7 +28,7 @@ class DumperTest extends TestCase '' => 'bar', 'foo' => '#bar', 'foo\'bar' => [], - 'bar' => [1, 'foo'], + 'bar' => [1, 'foo', ['a' => 'A']], 'foobar' => [ 'foo' => 'bar', 'bar' => [1, 'foo'], @@ -64,6 +64,8 @@ public function testIndentationInConstructor() bar: - 1 - foo + - + a: A foobar: foo: bar bar: @@ -107,7 +109,7 @@ public function testSpecifications() public function testInlineLevel() { $expected = <<<'EOF' -{ '': bar, foo: '#bar', "foo'bar": { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } +{ '': bar, foo: '#bar', "foo'bar": { }, bar: [1, foo, { a: A }], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } EOF; $this->assertEquals($expected, $this->dumper->dump($this->array, -10), '->dump() takes an inline level argument'); $this->assertEquals($expected, $this->dumper->dump($this->array, 0), '->dump() takes an inline level argument'); @@ -116,7 +118,7 @@ public function testInlineLevel() '': bar foo: '#bar' "foo'bar": { } -bar: [1, foo] +bar: [1, foo, { a: A }] foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } EOF; @@ -129,6 +131,7 @@ public function testInlineLevel() bar: - 1 - foo + - { a: A } foobar: foo: bar bar: [1, foo] @@ -144,6 +147,8 @@ public function testInlineLevel() bar: - 1 - foo + - + a: A foobar: foo: bar bar: @@ -163,6 +168,8 @@ public function testInlineLevel() bar: - 1 - foo + - + a: A foobar: foo: bar bar: @@ -379,8 +386,9 @@ public function testDumpingTaggedValueSequenceRespectsInlineLevel() new TaggedValue('user', [ 'username' => 'jane', ]), - new TaggedValue('user', [ - 'username' => 'john', + new TaggedValue('names', [ + 'john', + 'claire', ]), ]; @@ -389,8 +397,9 @@ public function testDumpingTaggedValueSequenceRespectsInlineLevel() $expected = <<assertSame($expected, $yaml); @@ -402,8 +411,9 @@ public function testDumpingTaggedValueSequenceWithInlinedTagValues() new TaggedValue('user', [ 'username' => 'jane', ]), - new TaggedValue('user', [ - 'username' => 'john', + new TaggedValue('names', [ + 'john', + 'claire', ]), ]; @@ -411,7 +421,7 @@ public function testDumpingTaggedValueSequenceWithInlinedTagValues() $expected = <<assertSame($expected, $yaml); @@ -423,8 +433,9 @@ public function testDumpingTaggedValueMapRespectsInlineLevel() 'user1' => new TaggedValue('user', [ 'username' => 'jane', ]), - 'user2' => new TaggedValue('user', [ - 'username' => 'john', + 'names1' => new TaggedValue('names', [ + 'john', + 'claire', ]), ]; @@ -433,8 +444,9 @@ public function testDumpingTaggedValueMapRespectsInlineLevel() $expected = <<assertSame($expected, $yaml); @@ -446,8 +458,9 @@ public function testDumpingTaggedValueMapWithInlinedTagValues() 'user1' => new TaggedValue('user', [ 'username' => 'jane', ]), - 'user2' => new TaggedValue('user', [ - 'username' => 'john', + 'names1' => new TaggedValue('names', [ + 'john', + 'claire', ]), ]; @@ -455,7 +468,7 @@ public function testDumpingTaggedValueMapWithInlinedTagValues() $expected = <<assertSame($expected, $yaml);