Skip to content

Commit 7830fa7

Browse files
committed
bug symfony#18840 [Yaml] properly handle unindented collections (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Yaml] properly handle unindented collections | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#8077 | License | MIT | Doc PR | Commits ------- 717e1a9 [Yaml] properly handle unindented collections
2 parents fe98cec + 717e1a9 commit 7830fa7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ private function isNextLineUnIndentedCollection()
725725
*/
726726
private function isStringUnIndentedCollectionItem()
727727
{
728-
return 0 === strpos($this->currentLine, '- ');
728+
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
729729
}
730730

731731
/**

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,34 @@ public function testSequenceInAMapping()
557557
);
558558
}
559559

560+
public function testSequenceInMappingStartedBySingleDashLine()
561+
{
562+
$yaml = <<<EOT
563+
a:
564+
-
565+
b:
566+
-
567+
bar: baz
568+
- foo
569+
d: e
570+
EOT;
571+
$expected = array(
572+
'a' => array(
573+
array(
574+
'b' => array(
575+
array(
576+
'bar' => 'baz',
577+
),
578+
),
579+
),
580+
'foo',
581+
),
582+
'd' => 'e',
583+
);
584+
585+
$this->assertSame($expected, $this->parser->parse($yaml));
586+
}
587+
560588
/**
561589
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
562590
*/

0 commit comments

Comments
 (0)