From c77fdcb2dc8ce5943e5fcd50147d7d7b6a7346b8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 1 Nov 2014 13:21:10 +0100 Subject: [PATCH] improve error message for multiple documents The YAML parser doesn't support multiple documents. This pull requests improves the error message when the parser detects multiple YAML documents. --- src/Symfony/Component/Yaml/Parser.php | 5 +++++ .../Component/Yaml/Tests/ParserTest.php | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 4b9b77a54d..10fcf192d5 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -193,6 +193,11 @@ class Parser } } } else { + // multiple documents are not supported + if ('---' === $this->currentLine) { + 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]))) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index d869b52407..b02dddfa02 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -482,6 +482,27 @@ EOF; $this->parser->parse($yaml); } + /** + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Multiple documents are not supported. + */ + public function testMultipleDocumentsNotSupportedException() + { + Yaml::parse(<<