Skip to content

Commit

Permalink
[Yaml] fix parse error when unindented collections contain a comment
Browse files Browse the repository at this point in the history
  • Loading branch information
wdiesveld authored and fabpot committed May 4, 2020
1 parent 469d82d commit 58bb2c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml
Expand Up @@ -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']]

0 comments on commit 58bb2c5

Please sign in to comment.