[Yaml] Emit {} instead of { } when dumping an empty map#64151
[Yaml] Emit {} instead of { } when dumping an empty map#64151ousamabenyounes wants to merge 1 commit intosymfony:8.1symfony/symfony:8.1from ousamabenyounes:fix/issue-64137ousamabenyounes/symfony:fix/issue-64137Copy head branch name to clipboard
{} instead of { } when dumping an empty map#64151Conversation
|
In the past, we shipped formatting changes in minor versions, not a bug fixes (this is not a bug after all. |
080e9aa to
0a8e381
Compare
Empty hashes/objects fall through to dumpHashArray() with an empty
$output, so sprintf('{ %s }', '') produced two spaces between the
braces. Mirror the empty-sequence form ([]) and emit '{}' instead,
which removes the pointless whitespace from dumped configs (Drupal-style
tooling re-formats every diff otherwise) and round-trips cleanly:
parse('{}') already returns [].
0a8e381 to
2411aef
Compare
|
The red
The "Docker registry 500" only applied to the very first run ( |
|
Please don't let your LLM reply instead of you, that's noisy. |
|
I've removed comments after noticing there were errors, and will keep future interactions direct and human-reviewed. I'm putting the necessary checks in place to avoid having to correct this kind of issue going forward. Apologies again, and thanks for the feedback. |
Inline::dumpHashArray()always wrapped its body withsprintf('{ %s }', ...), so an empty hash dumped as{ }(two spaces). Empty arrays go throughdumpArray(), which falls through todumpHashArray()when neither sequence nor populated, so they suffered from the same artefact.Mirror the empty-sequence form (
[]) and emit{}for empty maps, which is also whatInline::parse('{}')already produces. This removes pointless whitespace from dumped configs — tooling around YAML coding standards (e.g. Drupal config) re-formats every diff otherwise.Targeting
8.1rather than6.4per @stof:{ }is technically a valid YAML representation, this is a formatting cleanup, not a behavioural bug — patch versions on the LTS shouldn't move dumped output for projects asserting on it.Coverage: existing
DumperTestempty-map assertions are tightened from'{ }'to'{}', and the inline-level fixtures used intestInlineLevel/testIndentationInConstructor(which all contain a'foo\'bar' => []slot) are updated accordingly. A new['{}', []]and['{ foo: {} }', ['foo' => []]]are added toInlineTest::getTestsForDumpso both the bare and nested empty-map paths are covered fordump+parseround-trip.