Merge branch '2.3' into 2.7

* 2.3:
  [Yaml] Add regression test for comments indents
  Revert "bug #15860 [Yaml] Fix improper comments removal (ogizanagi)"
This commit is contained in:
Fabien Potencier 2015-10-02 14:36:41 +02:00
commit 34c8a7c51c
2 changed files with 38 additions and 37 deletions

View File

@ -375,9 +375,17 @@ class Parser
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
// Comments must not be removed inside a block scalar
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
while ($this->moveToNextLine()) {
$indent = $this->getCurrentLineIndentation();
if ($indent === $newIndent) {
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
}
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
$this->moveToPreviousLine();
break;
@ -388,6 +396,10 @@ class Parser
continue;
}
if ($removeComments && $this->isCurrentLineComment()) {
continue;
}
if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} elseif (0 == $indent) {

View File

@ -622,6 +622,32 @@ EOF;
$this->assertEquals(array('hash' => null), Yaml::parse($input));
}
public function testCommentAtTheRootIndent()
{
$this->assertEquals(array(
'services' => array(
'app.foo_service' => array(
'class' => 'Foo',
),
'app/bar_service' => array(
'class' => 'Bar',
),
),
), Yaml::parse(<<<EOF
# comment 1
services:
# comment 2
# comment 3
app.foo_service:
class: Foo
# comment 4
# comment 5
app/bar_service:
class: Bar
EOF
));
}
public function testStringBlockWithComments()
{
$this->assertEquals(array('content' => <<<EOT
@ -679,43 +705,6 @@ EOF
));
}
public function testSecondLevelFoldedStringBlockWithComments()
{
$this->assertEquals(array(
'pages' => array(
array(
'title' => 'some title',
'content' => <<<EOT
# comment 1
header
# comment 2
<body>
<h1>title</h1>
</body>
footer # comment3
EOT
),
),
), Yaml::parse(<<<EOF
pages:
-
title: some title
content: |
# comment 1
header
# comment 2
<body>
<h1>title</h1>
</body>
footer # comment3
EOF
));
}
public function testNestedFoldedStringBlockWithComments()
{
$this->assertEquals(array(array(