From 0ea2228228d5d54e1228068059a06b33c1519d59 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 26 May 2016 23:33:50 +0200 Subject: [PATCH] [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. --- src/Symfony/Component/Yaml/Parser.php | 2 +- src/Symfony/Component/Yaml/Tests/ParserTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index de1101f009..2b5cb79951 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -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.'); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 4ebee0fd89..53fe51a09a 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -1230,6 +1230,19 @@ EOT ), ); } + + public function testParseDateAsMappingValue() + { + $yaml = <<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