Skip to content

Commit 66bb94a

Browse files
committed
raise a parse error for duplicate keys
1 parent c90cd42 commit 66bb94a

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

UPGRADE-8.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,8 @@ VarExporter
307307
* Restrict `ProxyHelper::generateLazyProxy()` to generating abstraction-based lazy decorators; use native lazy proxies otherwise
308308
* Remove `LazyGhostTrait` and `LazyProxyTrait`, use native lazy objects instead
309309
* Remove `ProxyHelper::generateLazyGhost()`, use native lazy objects instead
310+
311+
Yaml
312+
----
313+
314+
* Remove support for parsing duplicate mapping keys whose value is `null`

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
8.0
5+
---
6+
7+
* Remove support for parsing duplicate mapping keys whose value is `null`
8+
49
7.3
510
---
611

src/Symfony/Component/Yaml/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private function doParse(string $value, int $flags): mixed
301301
// But overwriting is allowed when a merge node is used in current block.
302302
if ($allowOverwrite || !isset($data[$key])) {
303303
if (!$allowOverwrite && \array_key_exists($key, $data)) {
304-
trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1);
304+
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
305305
}
306306

307307
if (null !== $subTag) {
@@ -326,7 +326,7 @@ private function doParse(string $value, int $flags): mixed
326326
$data += $value;
327327
} elseif ($allowOverwrite || !isset($data[$key])) {
328328
if (!$allowOverwrite && \array_key_exists($key, $data)) {
329-
trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1);
329+
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
330330
}
331331

332332
// Spec: Keys MUST be unique; first one wins.
@@ -346,7 +346,7 @@ private function doParse(string $value, int $flags): mixed
346346
// But overwriting is allowed when a merge node is used in current block.
347347
if ($allowOverwrite || !isset($data[$key])) {
348348
if (!$allowOverwrite && \array_key_exists($key, $data)) {
349-
trigger_deprecation('symfony/yaml', '7.2', 'Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.', $key, $this->getRealCurrentLineNb() + 1);
349+
throw new ParseException(\sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
350350
}
351351

352352
$data[$key] = $value;

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
class ParserTest extends TestCase
2222
{
23-
use ExpectUserDeprecationMessageTrait;
24-
2523
private ?Parser $parser;
2624

2725
protected function setUp(): void
@@ -1059,12 +1057,9 @@ public static function getParseExceptionOnDuplicateData()
10591057
return $tests;
10601058
}
10611059

1062-
/**
1063-
* @group legacy
1064-
*/
10651060
public function testNullAsDuplicatedData()
10661061
{
1067-
$this->expectUserDeprecationMessage('Since symfony/yaml 7.2: Duplicate key "child" detected on line 4 whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated and will throw a ParseException in 8.0.');
1062+
$this->expectException(ParseException::class);
10681063

10691064
$yaml = <<<EOD
10701065
parent:

src/Symfony/Component/Yaml/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"require": {
1919
"php": ">=8.4",
20-
"symfony/deprecation-contracts": "^2.5|^3.0",
2120
"symfony/polyfill-ctype": "^1.8"
2221
},
2322
"require-dev": {

0 commit comments

Comments
 (0)