Skip to content

Commit

Permalink
improve error message for multiple documents
Browse files Browse the repository at this point in the history
The YAML parser doesn't support multiple documents. This pull requests
improves the error message when the parser detects multiple YAML
documents.
  • Loading branch information
xabbuh committed Nov 1, 2014
1 parent 97bb22c commit c77fdcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -193,6 +193,11 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
}
}
} 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]))) {
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Yaml/Tests/ParserTest.php
Expand Up @@ -482,6 +482,27 @@ public function testUnindentedCollectionException()
$this->parser->parse($yaml);
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Multiple documents are not supported.
*/
public function testMultipleDocumentsNotSupportedException()
{
Yaml::parse(<<<EOL
# Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
EOL
);
}

/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
Expand Down

0 comments on commit c77fdcb

Please sign in to comment.