8000 [Yaml] do not eagerly filter comment lines by xabbuh · Pull Request #25241 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] do not eagerly filter comment lines #25241

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
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
15 changes: 2 additions & 13 deletions src/Symfony/Component/Yaml/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,21 +601,10 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
continue;
}

// we ignore "comment" lines only when we are not inside a scalar block
if (empty($blockScalarIndentations) && $this->isCurrentLineComment()) {
// remember ignored comment lines (they are used later in nested
// parser calls to determine real line numbers)
//
// CAUTION: beware to not populate the global property here as it
// will otherwise influence the getRealCurrentLineNb() call here
// for consecutive comment lines and subsequent embedded blocks
$this->locallySkippedLineNumbers[] = $this->getRealCurrentLineNb();

continue;
}

if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} elseif ($this->isCurrentLineComment()) {
$data[] = $this->currentLine;
} elseif (0 == $indent) {
$this->moveToPreviousLine();

Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,24 @@ public function testMultiLineQuotedStringWithTrailingBackslash()
$this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml));
}

public function testCommentCharactersInMultiLineQuotedStrings()
{
$yaml = <<<YAML
foo:
foobar: 'foo
#bar'
bar: baz
YAML;
$expected = array(
'foo' => array(
'foobar' => 'foo #bar',
'bar' => 'baz',
),
);

$this->assertSame($expected, $this->parser->parse($yaml));
}

public function testParseMultiLineUnquotedString()
{
$yaml = <<<EOT
Expand Down
0