Skip to content

Commit

Permalink
[Yaml] properly handle unindented collections
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed May 22, 2016
1 parent 76223b2 commit 717e1a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -711,7 +711,7 @@ private function isNextLineUnIndentedCollection()
*/
private function isStringUnIndentedCollectionItem()
{
return 0 === strpos($this->currentLine, '- ');
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -557,6 +557,34 @@ public function testSequenceInAMapping()
);
}

public function testSequenceInMappingStartedBySingleDashLine()
{
$yaml = <<<EOT
a:
-
b:
-
bar: baz
- foo
d: e
EOT;
$expected = array(
'a' => array(
array(
'b' => array(
array(
'bar' => 'baz',
),
),
),
'foo',
),
'd' => 'e',
);

$this->assertSame($expected, $this->parser->parse($yaml));
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
Expand Down

0 comments on commit 717e1a9

Please sign in to comment.