Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f5edf2

Browse files
bug #25241 [Yaml] do not eagerly filter comment lines (xabbuh)
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] do not eagerly filter comment lines | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Trying to be clever by filtering commented lines inside `getNextEmbedBlock()` does not work as expected. The `#` may as well be part of a multi-line quoted string where it must not be treated as the beginning of a comment. Thus, we only must ensure that a comment-like line does not skip the process of getting the next line of the embed block. Commits ------- d594038 do not eagerly filter comment lines
2 parents f056b4e + d594038 commit 5f5edf2

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,21 +601,10 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
601601
continue;
602602
}
603603

604-
// we ignore "comment" lines only when we are not inside a scalar block
605-
if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) {
606-
// remember ignored comment lines (they are used later in nested
607-
// parser calls to determine real line numbers)
608-
//
609-
// CAUTION: beware to not populate the global property here as it
610-
// will otherwise influence the getRealCurrentLineNb() call here
611-
// for consecutive comment lines and subsequent embedded blocks
612-
$this->locallySkippedLineNumbers[] = $this->getRealCurrentLineNb();
613-
614-
continue;
615-
}
616-
617604
if ($indent >= $newIndent) {
618605
$data[] = substr($this->currentLine, $newIndent);
606+
} elseif ($this->isCurrentLineComment()) {
607+
$data[] = $this->currentLine;
619608
} elseif (0 == $indent) {
620609
$this->moveToPreviousLine();
621610

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,24 @@ public function testMultiLineQuotedStringWithTrailingBackslash()
15541554
$this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml));
15551555
}
15561556

1557+
public function testCommentCharactersInMultiLineQuotedStrings()
1558+
{
1559+
$yaml = <<<YAML
1560+
foo:
1561+
foobar: 'foo
1562+
#bar'
1563+
bar: baz
1564+
YAML;
1565+
$expected = array(
1566+
'foo' => array(
1567+
'foobar' => 'foo #bar',
1568+
'bar' => 'baz',
1569+
),
1570+
);
1571+
1572+
$this->assertSame($expected, $this->parser->parse($yaml));
1573+
}
1574+
15571575
public function testParseMultiLineUnquotedString()
15581576
{
15591577
$yaml = <<<EOT

0 commit comments

Comments
 (0)