Fixed parsing of leading blank lines in folded scalars. Closes #7989.
This commit is contained in:
parent
d2a542c5bb
commit
a5441b2d57
@ -419,6 +419,18 @@ class Parser
|
||||
return '';
|
||||
}
|
||||
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
$text = '';
|
||||
|
||||
// leading blank lines are consumed before determining indentation
|
||||
while ($notEOF && $isCurrentLineBlank) {
|
||||
// newline only if not EOF
|
||||
if ($notEOF = $this->moveToNextLine()) {
|
||||
$text .= "\n";
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
}
|
||||
}
|
||||
|
||||
// determine indentation if not specified
|
||||
if (0 === $indentation) {
|
||||
if (preg_match('/^ +/', $this->currentLine, $matches)) {
|
||||
@ -426,11 +438,9 @@ class Parser
|
||||
}
|
||||
}
|
||||
|
||||
$text = '';
|
||||
if ($indentation > 0) {
|
||||
$pattern = sprintf('/^ {%d}(.*)$/', $indentation);
|
||||
|
||||
$isCurrentLineBlank = $this->isCurrentLineBlank();
|
||||
while (
|
||||
$notEOF && (
|
||||
$isCurrentLineBlank ||
|
||||
|
@ -396,6 +396,27 @@ EOF;
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for issue #7989.
|
||||
*
|
||||
* @see https://github.com/symfony/symfony/issues/7989
|
||||
*/
|
||||
public function testBlockLiteralWithLeadingNewlines()
|
||||
{
|
||||
$yaml = <<<'EOF'
|
||||
foo: |-
|
||||
|
||||
|
||||
bar
|
||||
|
||||
EOF;
|
||||
$expected = array(
|
||||
'foo' => "\n\nbar"
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->parser->parse($yaml));
|
||||
}
|
||||
|
||||
public function testObjectSupportEnabled()
|
||||
{
|
||||
$input = <<<EOF
|
||||
|
Reference in New Issue
Block a user