From 31b0472331c4e87fff70628fbcef96f2d99a4c3f Mon Sep 17 00:00:00 2001 From: Roman Martinuk Date: Wed, 17 Mar 2021 18:58:33 +0300 Subject: [PATCH] fixed parser --- src/Symfony/Component/Yaml/Parser.php | 12 ++++++- .../Yaml/Tests/Fixtures/YtsBasicTests.yml | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 6d0d523265348..f26b90f1b00b0 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -169,7 +169,16 @@ private function doParse(string $value, int $flags) } // array - if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { + if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) { + // Inline first child + $currentLineNumber = $this->getRealCurrentLineNb(); + + $sequenceIndentation = \strlen($values['leadspaces']) + 1; + $sequenceYaml = substr($this->currentLine, $sequenceIndentation); + $sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true); + + $data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags); + } elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { $data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags); } elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) { $data[] = new TaggedValue( @@ -604,6 +613,7 @@ private function getNextEmbedBlock(int $indentation = null, bool $inSequence = f } $data = []; + if ($this->getCurrentLineIndentation() >= $newIndent) { $data[] = substr($this->currentLine, $newIndent); } elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) { diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.yml index 1a08d8ea9fddf..621e224490da8 100644 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.yml +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.yml @@ -200,3 +200,37 @@ php: | 'age' => 38 ] ] +--- +test: Inline first element in sequence blocks 1 +yaml: | + - - s1_i1 + - s1_i2 + - s2 +php: | + [ + [ + "s1_i1", + "s1_i2" + ], + "s2" + ] +--- +test: Inline first element in sequence blocks 2 +yaml: | + - - s1_i1 + - - s1_i1_1 + - s1_i1_2 + - s1_i2 + - s2 +php: | + [ + [ + "s1_i1", + [ + "s1_i1_1", + "s1_i1_2", + ], + "s1_i2" + ], + "s2" + ]