Skip to content

Commit 717e1a9

Browse files
committed
[Yaml] properly handle unindented collections
1 parent 76223b2 commit 717e1a9

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
@@ -711,7 +711,7 @@ private function isNextLineUnIndentedCollection()
711711
*/
712712
private function isStringUnIndentedCollectionItem()
713713
{
714-
return 0 === strpos($this->currentLine, '- ');
714+
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
715715
}
716716

717717
/**

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)