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:
Christian Flothmann 2014-11-01 13:21:10 +01:00
parent 97bb22c48c
commit c77fdcb2dc
2 changed files with 26 additions and 0 deletions

View File

@ -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]))) {

View File

@ -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
*/