From 1a58df87cae70791865b73f2c03d15265eb60a51 Mon Sep 17 00:00:00 2001 From: NickSdot Date: Mon, 21 Aug 2023 22:05:22 +0800 Subject: [PATCH] Fix block scalar array parsing --- src/Symfony/Component/Yaml/Parser.php | 7 +++- .../Component/Yaml/Tests/ParserTest.php | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index d8886bb1860b..e4bacd7856c7 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -199,9 +199,8 @@ private function doParse(string $value, int $flags) || self::preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P.+?))?\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); } @@ -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; } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 98e5e73ec53e..741a6ad83c99 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -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 */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy