Skip to content

Commit

Permalink
bug #52408 [Yaml] Fix block scalar array parsing (NickSdot)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

[Yaml] Fix block scalar array parsing

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

Commits
-------

1a58df8 Fix block scalar array parsing
  • Loading branch information
nicolas-grekas committed Nov 2, 2023
2 parents 756236a + 1a58df8 commit fc22954
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -199,9 +199,8 @@ private function doParse(string $value, int $flags)
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
)
) {
// this is a compact notation element, add to next block and parse
$block = $values['value'];
if ($this->isNextLineIndented()) {
if ($this->isNextLineIndented() || isset($matches['value']) && '>-' === $matches['value']) {
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
}

Expand Down Expand Up @@ -949,6 +948,10 @@ private function isNextLineIndented(): bool
} while (!$EOF && ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()));

if ($EOF) {
for ($i = 0; $i < $movements; ++$i) {
$this->moveToPreviousLine();
}

return false;
}

Expand Down
38 changes: 38 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -2690,6 +2690,44 @@ public static function circularReferenceProvider()
return $tests;
}

public function testBlockScalarArray()
{
$yaml = <<<'YAML'
anyOf:
- $ref: >-
#/string/bar
anyOfMultiline:
- $ref: >-
#/string/bar
second line
nested:
anyOf:
- $ref: >-
#/string/bar
YAML;
$expected = [
'anyOf' => [
0 => [
'$ref' => '#/string/bar',
],
],
'anyOfMultiline' => [
0 => [
'$ref' => '#/string/bar second line',
],
],
'nested' => [
'anyOf' => [
0 => [
'$ref' => '#/string/bar',
],
],
],
];

$this->assertSame($expected, $this->parser->parse($yaml));
}

/**
* @dataProvider indentedMappingData
*/
Expand Down

0 comments on commit fc22954

Please sign in to comment.