diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 2771f51fd2..6b2cc72aed 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -51,13 +51,13 @@ class Parser */ public function parse($value, $exceptionOnInvalidType = false, $objectSupport = false) { - $this->currentLineNb = -1; - $this->currentLine = ''; - $this->lines = explode("\n", $this->cleanup($value)); - if (!preg_match('//u', $value)) { throw new ParseException('The YAML value does not appear to be valid UTF-8.'); } + $this->currentLineNb = -1; + $this->currentLine = ''; + $value = $this->cleanup($value); + $this->lines = explode("\n", $value); if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); @@ -197,9 +197,8 @@ class Parser throw new ParseException('Multiple documents are not supported.'); } - // 1-liner optionally followed by newline - $lineCount = count($this->lines); - if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) { + // 1-liner optionally followed by newline(s) + if ($this->lines[0] === trim($value)) { try { $value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $this->refs); } catch (ParseException $e) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index aca190ac8b..5c71889cb2 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -135,6 +135,14 @@ EOF; ); $tests['Literal block chomping strip with multiple trailing newlines'] = array($expected, $yaml); + $yaml = <<<'EOF' +{} + + +EOF; + $expected = array(); + $tests['Literal block chomping strip with multiple trailing newlines after a 1-liner'] = array($expected, $yaml); + $yaml = <<<'EOF' foo: |- one