10000 [Yaml] Fix improper comments removal inside strings · symfony/symfony@0e24fc5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e24fc5

Browse files
author
maxime.steinhausser
committed
[Yaml] Fix improper comments removal inside strings
1 parent bd415c6 commit 0e24fc5

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,9 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
337337

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

340-
// Comments must not be removed inside a string block (ie. after a line ending with "|")
341-
$removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~';
342-
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
343-
344340
while ($this->moveToNextLine()) {
345341
$indent = $this->getCurrentLineIndentation();
346342

347-
if ($indent === $newIndent) {
348-
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
349-
}
350-
351343
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
352344
$this->moveToPreviousLine();
353345
break;
@@ -358,10 +350,6 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
358350
continue;
359351
}
360352

361-
if ($removeComments && $this->isCurrentLineComment()) {
362-
continue;
363-
}
364-
365353
if ($indent >= $newIndent) {
366354
$data[] = substr($this->currentLine, $newIndent);
367355
} elseif (0 == $indent) {

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,43 @@ public function testFoldedStringBlockWithComments()
617617
));
618618
}
619619

620+
public function testSecondLevelFoldedStringBlockWithComments()
621+
{
622+
$this->assertEquals(array(
623+
'pages' => array(
624+
array(
625+
'title' => 'some title',
626+
'content' => <<<EOT
627+
# comment 1
628+
header
629+
630+
# comment 2
631+
<body>
632+
<h1>title</h1>
633+
</body>
634+
635+
footer # comment3
636+
EOT
637+
),
638+
),
639+
), Yaml::parse(<<<EOF
640+
pages:
641+
-
642+
title: some title
643+
content: |
644+
# comment 1
645+
header
646+
647+
# comment 2
648+
<body>
649+
<h1>title</h1>
650+
</body>
651+
652+
footer # comment3
653+
EOF
654+
));
655+
}
656+
620657
public function testNestedFoldedStringBlockWithComments()
621658
{
622659
$this->assertEquals(array(array(

0 commit comments

Comments
 (0)
0