[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:
parent
08f696c3e6
commit
adc6b3067d
@ -234,7 +234,7 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1-liner optionally followed by newline(s)
|
// 1-liner optionally followed by newline(s)
|
||||||
if ($this->lines[0] === trim($value)) {
|
if (is_string($value) && $this->lines[0] === trim($value)) {
|
||||||
try {
|
try {
|
||||||
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
|
$value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs);
|
||||||
} catch (ParseException $e) {
|
} catch (ParseException $e) {
|
||||||
|
@ -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.
|
* > 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
|
* > In such a case the YAML processor may continue, ignoring the second
|
||||||
|
Reference in New Issue
Block a user