diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index efaaeaf710..52dedfe078 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -468,13 +468,13 @@ class Parser } $isCurrentLineBlank = $this->isCurrentLineBlank(); - $text = ''; + $blockLines = array(); // leading blank lines are consumed before determining indentation while ($notEOF && $isCurrentLineBlank) { // newline only if not EOF if ($notEOF = $this->moveToNextLine()) { - $text .= "\n"; + $blockLines[] = ''; $isCurrentLineBlank = $this->isCurrentLineBlank(); } } @@ -495,37 +495,59 @@ class Parser preg_match($pattern, $this->currentLine, $matches) ) ) { - if ($isCurrentLineBlank) { - $text .= substr($this->currentLine, $indentation); + if ($isCurrentLineBlank && strlen($this->currentLine) > $indentation) { + $blockLines[] = substr($this->currentLine, $indentation); + } elseif ($isCurrentLineBlank) { + $blockLines[] = ''; } else { - $text .= $matches[1]; + $blockLines[] = $matches[1]; } // newline only if not EOF if ($notEOF = $this->moveToNextLine()) { - $text .= "\n"; $isCurrentLineBlank = $this->isCurrentLineBlank(); } } } elseif ($notEOF) { - $text .= "\n"; + $blockLines[] = ''; } if ($notEOF) { + $blockLines[] = ''; $this->moveToPreviousLine(); } // folded style if ('>' === $style) { - // folded lines - // replace all non-leading/non-trailing single newlines with spaces - preg_match('/(\n*)$/', $text, $matches); - $text = preg_replace('/(? +

A heading

+ + +EOT; + + $this->assertSame( + array( + 'test' => <<A heading + +EOT + , + ), + $this->parser->parse($yaml) + ); + } + + public function testAdditionallyIndentedLinesAreParsedAsNewLinesInFoldedBlocks() + { + $yaml = << +

A heading

+ + +EOT; + + $this->assertSame( + array( + 'test' => <<A heading +
    +
  • a list
  • +
  • may be a good example
  • +
+EOT + , + ), + $this->parser->parse($yaml) + ); + } } class B