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
This commit is contained in:
commit
5f5edf26f2
@ -601,21 +601,10 @@ class Parser
|
|||||||
continue;
|
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) {
|
if ($indent >= $newIndent) {
|
||||||
$data[] = substr($this->currentLine, $newIndent);
|
$data[] = substr($this->currentLine, $newIndent);
|
||||||
|
} elseif ($this->isCurrentLineComment()) {
|
||||||
|
$data[] = $this->currentLine;
|
||||||
} elseif (0 == $indent) {
|
} elseif (0 == $indent) {
|
||||||
$this->moveToPreviousLine();
|
$this->moveToPreviousLine();
|
||||||
|
|
||||||
|
@ -1554,6 +1554,24 @@ YAML;
|
|||||||
$this->assertSame(array('foobar' => 'foobar'), $this->parser->parse($yaml));
|
$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()
|
public function testParseMultiLineUnquotedString()
|
||||||
{
|
{
|
||||||
$yaml = <<<EOT
|
$yaml = <<<EOT
|
||||||
|
Reference in New Issue
Block a user