[Yaml] throw a ParseException on invalid data type

Without this check, PHP would trigger a warning when an array was passed
to `trim()`. The parser must throw a `ParseException` instance on a
malformed YAML string instead.
This commit is contained in:
Christian Flothmann 2015-07-22 08:30:32 +02:00 committed by Fabien Potencier
parent 08f696c3e6
commit adc6b3067d
2 changed files with 16 additions and 1 deletions

View File

@ -234,7 +234,7 @@ class Parser
}
// 1-liner optionally followed by newline(s)
if ($this->lines[0] === trim($value)) {
if (is_string($value) && $this->lines[0] === trim($value)) {
try {
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
} catch (ParseException $e) {

View File

@ -551,6 +551,21 @@ EOF
);
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage missing colon
*/
public function testScalarInSequence()
{
Yaml::parse(<<<EOF
foo:
- bar
"missing colon"
foo: bar
EOF
);
}
/**
* > It is an error for two equal keys to appear in the same mapping node.
* > In such a case the YAML processor may continue, ignoring the second