Closed
Description
Symfony version(s) affected
>=3.4.5
Description
\Symfony\Component\Yaml\Dumper::dump
only checks for leading spaces when deciding whether to add a block indentation indicator. If the value begins with a newline followed by spaces then the indicator isn't added.
https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Yaml/Dumper.php#L76
How to reproduce
// Create dumper with 2-space indentation.
$dumper = new \Symfony\Component\Yaml\Dumper(2);
// Prepare value beginning with newline followed by four spaces.
$data = ['key' => "\n multiline value\nwith leading newline\nfollowed by spaces"];
// Dump the value to YAML.
$dumper->dump($data2, 1, 0, \Symfony\Component\Yaml\Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
Result:
key: |-
multiline value
with leading newline
followed by spaces
Expected result:
key: |2-
multiline value
with leading newline
followed by spaces
Possible Solution
Remove leading newlines when determining the value of $blockIndentationIndicator
.
Additional Context
No response