From 58bb2c52ac73036262f5b60872edc8a6e8bbe0a9 Mon Sep 17 00:00:00 2001 From: Wouter Diesveld Date: Mon, 4 May 2020 11:46:19 +0200 Subject: [PATCH] [Yaml] fix parse error when unindented collections contain a comment --- src/Symfony/Component/Yaml/Parser.php | 6 ++++++ .../Component/Yaml/Tests/Fixtures/sfComments.yml | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index f1cb6b57aa8d..39116d84247a 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -619,8 +619,14 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false) } $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem(); + $isItComment = $this->isCurrentLineComment(); while ($this->moveToNextLine()) { + if ($isItComment && !$isItUnindentedCollection) { + $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem(); + $isItComment = $this->isCurrentLineComment(); + } + $indent = $this->getCurrentLineIndentation(); if ($isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) { diff --git a/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml b/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml index af3ab38597a9..4b0c91c9b1eb 100644 --- a/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml +++ b/src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml @@ -74,3 +74,17 @@ yaml: | 'foo #': baz php: | ['foo #' => 'baz'] +--- +test: Comment before first item in unindented collection +brief: > + Comment directly before unindented collection is allowed +yaml: | + collection1: + # comment + - a + - b + collection2: + - a + - b +php: | + ['collection1' => ['a', 'b'], 'collection2' => ['a', 'b']]