You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Parser.php
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -299,7 +299,11 @@ private function doParse(string $value, int $flags): mixed
299
299
if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
300
300
// Spec: Keys MUST be unique; first one wins.
301
301
// But overwriting is allowed when a merge node is used in current block.
302
-
if ($allowOverwrite || !\array_key_exists($key, $data)) {
302
+
if ($allowOverwrite || !isset($data[$key])) {
303
+
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);
305
+
}
306
+
303
307
if (null !== $subTag) {
304
308
$data[$key] = newTaggedValue($subTag, '');
305
309
} else {
@@ -320,7 +324,11 @@ private function doParse(string $value, int $flags): mixed
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);
330
+
}
331
+
324
332
// Spec: Keys MUST be unique; first one wins.
325
333
// But overwriting is allowed when a merge node is used in current block.
326
334
if (null !== $subTag) {
@@ -336,7 +344,11 @@ private function doParse(string $value, int $flags): mixed
// But overwriting is allowed when a merge node is used in current block.
339
-
if ($allowOverwrite || !\array_key_exists($key, $data)) {
347
+
if ($allowOverwrite || !isset($data[$key])) {
348
+
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);
@@ -1026,15 +1029,24 @@ public static function getParseExceptionOnDuplicateData()
1026
1029
EOD;
1027
1030
$tests[] = [$yaml, 'child_sequence', 6];
1028
1031
1032
+
return$tests;
1033
+
}
1034
+
1035
+
/**
1036
+
* @group legacy
1037
+
*/
1038
+
publicfunctiontestNullAsDuplicatedData()
1039
+
{
1040
+
$this->expectDeprecation('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.');
0 commit comments