Skip to content

Commit 1a58df8

Browse files
NickSdotxabbuh
authored andcommitted
Fix block scalar array parsing
1 parent f834fb5 commit 1a58df8

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/Symfony/Component/Yaml/Parser.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ private function doParse(string $value, int $flags)
199199
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
200200
)
201201
) {
202-
// this is a compact notation element, add to next block and parse
203202
$block = $values['value'];
204-
if ($this->isNextLineIndented()) {
203+
if ($this->isNextLineIndented() || isset($matches['value']) && '>-' === $matches['value']) {
205204
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
206205
}
207206

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

951950
if ($EOF) {
951+
for ($i = 0; $i < $movements; ++$i) {
952+
$this->moveToPreviousLine();
953+
}
954+
952955
return false;
953956
}
954957

src/Symfony/Component/Yaml/Tests/ParserTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,44 @@ public static function circularReferenceProvider()
26902690
return $tests;
26912691
}
26922692

2693+
public function testBlockScalarArray()
2694+
{
2695+
$yaml = <<<'YAML'
2696+
anyOf:
2697+
- $ref: >-
2698+
#/string/bar
2699+
anyOfMultiline:
2700+
- $ref: >-
2701+
#/string/bar
2702+
second line
2703+
nested:
2704+
anyOf:
2705+
- $ref: >-
2706+
#/string/bar
2707+
YAML;
2708+
$expected = [
2709+
'anyOf' => [
2710+
0 => [
2711+
'$ref' => '#/string/bar',
2712+
],
2713+
],
2714+
'anyOfMultiline' => [
2715+
0 => [
2716+
'$ref' => '#/string/bar second line',
2717+
],
2718+
],
2719+
'nested' => [
2720+
'anyOf' => [
2721+
0 => [
2722+
'$ref' => '#/string/bar',
2723+
],
2724+
],
2725+
],
2726+
];
2727+
2728+
$this->assertSame($expected, $this->parser->parse($yaml));
2729+
}
2730+
26932731
/**
26942732
* @dataProvider indentedMappingData
26952733
*/

0 commit comments

Comments
 (0)