Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc22954

Browse filesBrowse files
bug #52408 [Yaml] Fix block scalar array parsing (NickSdot)
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
2 parents 756236a + 1a58df8 commit fc22954
Copy full SHA for fc22954

File tree

Expand file treeCollapse file tree

2 files changed

+43
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-2
lines changed

‎src/Symfony/Component/Yaml/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+5-2Lines changed: 5 additions & 2 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/ParserTest.php
+38Lines changed: 38 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.