8000 Revert "bug #15860 [Yaml] Fix improper comments removal (ogizanagi)" · symfony/symfony@510fdea · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 510fdea

Browse files
committed
Revert "bug #15860 [Yaml] Fix improper comments removal (ogizanagi)"
This reverts commit 150f52f, reversing changes made to 74af02a.
1 parent 17edafd commit 510fdea

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

src/Symfony/Component/Yaml/Parser.php

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

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

342< 8000 /td>+
// Comments must not be removed inside a block scalar
343+
$removeCommentsPattern = '~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~';
344+
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
345+
342346
while ($this->moveToNextLine()) {
343347
$indent = $this->getCurrentLineIndentation();
344348

349+
if ($indent === $newIndent) {
350+
$removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
351+
}
352+
345353
if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine) && $newIndent === $indent) {
346354
$this->moveToPreviousLine();
347355
break;
@@ -352,6 +360,10 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
352360
continue;
353361
}
354362

363+
if ($removeComments && $this->isCurrentLineComment()) {
364+
continue;
365+
}
366+
355367
if ($indent >= $newIndent) {
356368
$data[] = substr($this->currentLine, $newIndent);
357369
} elseif (0 == $indent) {

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -617,43 +617,6 @@ 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-
657620
public function testNestedFoldedStringBlockWithComments()
658621
{
659622
$this->assertEquals(array(array(

0 commit comments

Comments
 (0)
0