Repository navigation
[Yaml] Do not treat quoted << keys as merge keys - #66621
Merged
Merged
Conversation
Only a plain `<<` key is a merge key: a quoted or `!!str` one is now kept as a key named `<<`, so the output of the Dumper parses back. In flow mappings, a merge key with a scalar value now throws a ParseException instead of a TypeError, and merge keys work with PARSE_OBJECT_FOR_MAP.
nicolas-grekas
force-pushed
the
yaml-quoted-merge-key
branch
from
October 5, 2026 04:37
effe7d2 to
d4f1d9b
Compare
Member
|
I updated the PR: a |
Member
|
Thank you @kevin9327. |
This was referenced Oct 14, 2026
Merged
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In YAML, only a plain
<<key is a merge key.'<<'and"<<"are ordinary string keys. The parser treated quoted ones as merge keys too. As a result, the Dumper's own output can't always be read back, even though the Dumper already quotes the key:The second example also shows that in inline mappings, a real merge key with a scalar value (
{ <<: foo }), or a sequence of scalars ({ <<: [foo] }), crashed with aTypeError. The block parser already throws aParseExceptionin those cases, and now the inline parser does the same.In
Parser, the merge-key check now looks at the raw key text ('<<' === $values['key']). InInline::parseMapping(), it uses the existing$isKeyQuoted. All the'<<' === $keychecks go through the new$isMergeKeyvariable.I found this by round-tripping random arrays through
Yaml::dump()andYaml::parse(). With the patch applied, a few hundred thousand cases on 6.4 came back identical. The new tests inInlineTest,ParserTestandDumperTestfail without the fix, and the Yaml test suite passes with it.This also means that a quoted
'<<'or"<<"key with a mapping value, which was merged before, is now kept as a key named<<, as YAML 1.1 and PyYAML do. So is!!str <<.Merge-up to 8.2: in
Parser.php, keep the$isMergeKeylines and drop theumodifier of#^&(?P<ref>[^ ]+)#, as 8.2 does. On 7.4, 8.1 and 8.2,DumperTestconflicts because both sides add a method at the end of the class: keep both.