Fixed parsing of leading blank lines in folded scalars. Closes #7989.

This commit is contained in:
Erin Millard 2013-05-10 10:09:46 +10:00
parent d2a542c5bb
commit a5441b2d57
2 changed files with 33 additions and 2 deletions

View File

@ -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 ||

View File

@ -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