bug #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 | #8077
| License       | MIT
| Doc PR        |

Commits
-------

717e1a9 [Yaml] properly handle unindented collections
This commit is contained in:
Fabien Potencier 2016-05-23 11:02:43 +02:00
commit 7830fa7dbd
2 changed files with 29 additions and 1 deletions

View File

@ -725,7 +725,7 @@ class Parser
*/
private function isStringUnIndentedCollectionItem()
{
return 0 === strpos($this->currentLine, '- ');
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
}
/**

View File

@ -557,6 +557,34 @@ EOF
);
}
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
*/