diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 1e88f85d4a..4a82b784bc 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -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 || diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 4eea6d5308..5e0e7634a6 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -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 = <<