diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 62eab04571df1..c9edde83a873b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG invokable Kernel class, and register `FrameworkBundle` by default when the `bundles.php` file is missing * [BC BREAK] The `secrets:decrypt-to-local` command terminates with a non-zero exit code when a secret could not be read * Deprecate making `cache.app` adapter taggable, use the `cache.app.taggable` adapter instead + * Enable `json_decode_detailed_errors` in the default serializer context in debug mode by default when `seld/jsonlint` is installed 7.1 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 42181d7acd1d3..ed7aff37414b1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1126,6 +1126,10 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e ->prototype('variable')->end() ->end() ->end() + ->validate() + ->ifTrue(fn ($v) => $this->debug && class_exists(JsonParser::class) && !isset($v['default_context'][JsonDecode::DETAILED_ERROR_MESSAGES])) + ->then(function ($v) { $v['default_context'][JsonDecode::DETAILED_ERROR_MESSAGES] = true; return $v; }) + ->end() ->end() ->end() ; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index bad27f8ee8fee..948df2cd951c7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -673,6 +673,30 @@ public function testScopedHttpClientsInheritRateLimiterAndRetryFailedConfigurati $this->assertSame(999, $scopedClients['qux']['retry_failed']['delay']); } + public function testSerializerJsonDetailedErrorMessagesEnabledByDefaultWithDebugEnabled() + { + $processor = new Processor(); + $config = $processor->processConfiguration(new Configuration(true), [ + [ + 'serializer' => null, + ], + ]); + + $this->assertSame([JsonDecode::DETAILED_ERROR_MESSAGES => true], $config['serializer']['default_context'] ?? []); + } + + public function testSerializerJsonDetailedErrorMessagesNotSetByDefaultWithDebugDisabled() + { + $processor = new Processor(); + $config = $processor->processConfiguration(new Configuration(false), [ + [ + 'serializer' => null, + ], + ]); + + $this->assertSame([], $config['serializer']['default_context'] ?? []); + } + protected static function getBundleDefaultConfig() { return [