8000 [Yaml] Fix improper comments removal by ogizanagi · Pull Request #15860 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] Fix improper comments removal #15860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,9 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)

$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);

// Comments must not be removed inside a string block (ie. after a line ending with "|")
$removeCommentsPattern = '~'.self::FOLDED_SCALAR_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;
Expand All @@ -358,10 +350,6 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
continue;
}

if ($removeComments && $this->isCurrentLineComment()) {
continue;
}

if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} elseif (0 == $indent) {
Expand Down
37 changes: 37 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,43 @@ public function testFoldedStringBlockWithComments()
));
}

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(
Expand Down
0