Skip to content

Commit

Permalink
bug #18840 [Yaml] properly handle unindented collections (xabbuh)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed May 23, 2016
2 parents fe98cec + 717e1a9 commit 7830fa7
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 @@ -725,7 +725,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 7830fa7

Please sign in to comment.