8000 [FrameworkBundle] Enable `json_decode_detailed_errors` in dev by default · symfony/symfony@2a551c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a551c2

Browse files
committed
[FrameworkBundle] Enable json_decode_detailed_errors in dev by default
1 parent b2a17ea commit 2a551c2

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add native return type to `Translator` and to `Application::reset()`
88
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
9+
* Enable `json_decode_detailed_errors` context for Serializer by default if `kernel.debug` is true and the `seld/jsonlint` package is installed
910

1011
6.3
1112
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Annotations\Annotation;
1515
use Doctrine\DBAL\Connection;
1616
use Psr\Log\LogLevel;
17+
use Seld\JsonLint\JsonParser;
1718
use Symfony\Bundle\FullStack;
1819
use Symfony\Component\Asset\Package;
1920
use Symfony\Component\AssetMapper\AssetMapper;
@@ -41,6 +42,7 @@
4142
use Symfony\Component\RemoteEvent\RemoteEvent;
4243
use Symfony\Component\Scheduler\Schedule;
4344
use Symfony\Component\Semaphore\Semaphore;
45+
use Symfony\Component\Serializer\Encoder\JsonDecode;
4446
use Symfony\Component\Serializer\Serializer;
4547
use Symfony\Component\Translation\Translator;
4648
use Symfony\Component\Uid\Factory\UuidFactory;
@@ -1123,6 +1125,10 @@ private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $e
11231125
->arrayNode('default_context')
11241126
->normalizeKeys(false)
11251127
->useAttributeAsKey('name')
1128+
->beforeNormalization()
1129+
->ifTrue(fn (array $v) => $this->debug && class_exists(JsonParser::class))
1130+
->then(fn (array $v) => $v + [JsonDecode::DETAILED_ERROR_MESSAGES => true])
1131+
->end()
11261132
->defaultValue([])
11271133
->prototype('variable')->end()
11281134
->end()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
use Symfony\Component\Notifier\Notifier;
2828
use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter;
2929
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
30+
use Symfony\Component\Serializer\Encoder\JsonDecode;
3031
use Symfony\Component\Uid\Factory\UuidFactory;
3132

3233
class ConfigurationTest extends TestCase
3334
{
3435
public function testDefaultConfig()
3536
{
3637
$processor = new Processor();
37-
$config = $processor->processConfiguration(new Configuration(true), [['http_method_override' => false, 'secret' => 's3cr3t']]);
38+
$config = $processor->processConfiguration(new Configuration(true), [['http_method_override' => false, 'secret' => 's3cr3t', 'serializer' => ['default_context' => ['foo' => 'bar']]]]);
3839

3940
$this->assertEquals(self::getBundleDefaultConfig(), $config);
4041
}
@@ -563,8 +564,8 @@ protected static function getBundleDefaultConfig()
563564
'enabled' => true,
564565
],
565566
'serializer' => [
566-
'default_context' => [],
567-
'enabled' => !class_exists(FullStack::class),
567+
'default_context' => ['foo' => 'bar', JsonDecode::DETAILED_ERROR_MESSAGES => true],
568+
'enabled' => true,
568569
'enable_annotations' => !class_exists(FullStack::class),
569570
'mapping' => ['paths' => []],
570571
],

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"require-dev": {
3636
"doctrine/annotations": "^1.13.1|^2",
3737
"doctrine/persistence": "^1.3|^2|^3",
38+
"seld/jsonlint": "^1.10",
3839
"symfony/asset": "^5.4|^6.0|^7.0",
3940
"symfony/asset-mapper": "^6.3|^7.0",
4041
"symfony/browser-kit": "^5.4|^6.0|^7.0",
@@ -58,7 +59,7 @@
5859
"symfony/scheduler": "^6.3|^7.0",
5960
"symfony/security-bundle": "^5.4|^6.0|^7.0",
6061
"symfony/semaphore": "^5.4|^6.0|^7.0",
61-
"symfony/serializer": "^6.3|^7.0",
62+
"symfony/serializer": "^6.4|^7.0",
6263
"symfony/stopwatch": "^5.4|^6.0|^7.0",
6364
"symfony/string": "^5.4|^6.0|^7.0",
6465
"symfony/translation": "^6.2.8|^7.0",
@@ -90,7 +91,7 @@
9091
"symfony/mime": "<6.2",
9192
"symfony/property-info": "<5.4",
9293
"symfony/property-access": "<5.4",
93-
"symfony/serializer": "<6.3",
94+
"symfony/serializer": "<6.4",
9495
"symfony/security-csrf": "<5.4",
9596
"symfony/security-core": "<5.4",
9697
"symfony/stopwatch": "<5.4",

0 commit comments

Comments
 (0)
0