[Yaml] search for colons in strings only
Since the parser is able to return `\DateTime` instances when the `Yaml::PARSE_DATETIME` flag is passed, we need to ensure that the parsed value actually is a string before passing the parsed value to string functions.
This commit is contained in:
parent
91a4de32c3
commit
0ea2228228
@ -539,7 +539,7 @@ class Parser
|
||||
try {
|
||||
$parsedValue = Inline::parse($value, $flags, $this->refs);
|
||||
|
||||
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
|
||||
if ('mapping' === $context && is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
|
||||
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
|
||||
}
|
||||
|
||||
|
@ -1230,6 +1230,19 @@ EOT
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseDateAsMappingValue()
|
||||
{
|
||||
$yaml = <<<EOT
|
||||
date: 2002-12-14
|
||||
EOT;
|
||||
$expectedDate = new \DateTime();
|
||||
$expectedDate->setTimeZone(new \DateTimeZone('UTC'));
|
||||
$expectedDate->setDate(2002, 12, 14);
|
||||
$expectedDate->setTime(0, 0, 0);
|
||||
|
||||
$this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
|
||||
}
|
||||
}
|
||||
|
||||
class B
|
||||
|
Reference in New Issue
Block a user