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.
This commit is contained in:
parent
97bb22c48c
commit
c77fdcb2dc
@ -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]))) {
|
||||
|
@ -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(<<<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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user