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:
commit
34c8a7c51c
@ -375,9 +375,17 @@ class Parser
|
|||||||
|
|
||||||
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
|
$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()) {
|
while ($this->moveToNextLine()) {
|
||||||
$indent = $this->getCurrentLineIndentation();
|
$indent = $this->getCurrentLineIndentation();
|
||||||
|
|
||||||
|
if ($indent === $newIndent) {
|
||||||
|
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
|
||||||
|
}
|
||||||
|
|
||||||
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
|
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
|
||||||
$this->moveToPreviousLine();
|
$this->moveToPreviousLine();
|
||||||
break;
|
break;
|
||||||
@ -388,6 +396,10 @@ class Parser
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($removeComments && $this->isCurrentLineComment()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($indent >= $newIndent) {
|
if ($indent >= $newIndent) {
|
||||||
$data[] = substr($this->currentLine, $newIndent);
|
$data[] = substr($this->currentLine, $newIndent);
|
||||||
} elseif (0 == $indent) {
|
} elseif (0 == $indent) {
|
||||||
|
@ -622,6 +622,32 @@ EOF;
|
|||||||
$this->assertEquals(array('hash' => null), Yaml::parse($input));
|
$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()
|
public function testStringBlockWithComments()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array('content' => <<<EOT
|
$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()
|
public function testNestedFoldedStringBlockWithComments()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(array(
|
$this->assertEquals(array(array(
|
||||||
|
Reference in New Issue
Block a user