8000 [Yaml] search for colons in strings only · symfony/symfony@0ea2228 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ea2228

Browse files
committed
[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.
1 parent 91a4de3 commit 0ea2228

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ private function parseValue($value, $flags, $context)
539539
try {
540540
$parsedValue = Inline::parse($value, $flags, $this->refs);
541541

542-
if ('mapping' === $context && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
542+
if ('mapping' === $context && is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
543543
throw new ParseException('A colon cannot be used in an unquoted mapping value.');
544544
}
545545

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,19 @@ public function getInvalidBinaryData()
12301230
),
12311231
);
12321232
}
1233+
1234+
public function testParseDateAsMappingValue()
1235+
{
1236+
$yaml = <<<EOT
1237+
date: 2002-12-14
1238+
EOT;
1239+
$expectedDate = new \DateTime();
1240+
$expectedDate->setTimeZone(new \DateTimeZone('UTC'));
1241+
$expectedDate->setDate(2002, 12, 14);
1242+
$expectedDate->setTime(0, 0, 0);
1243+
1244+
$this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
1245+
}
12331246
}
12341247

12351248
class B

0 commit comments

Comments
 (0)
0