Skip to content

Commit 922f1b0

Browse files
committed
bug symfony#18899 [Yaml] search for colons in strings only (xabbuh)
This PR was merged into the 3.1 branch. Discussion ---------- [Yaml] search for colons in strings only | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#18897 | License | MIT | Doc PR | 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. Commits ------- 0ea2228 [Yaml] search for colons in strings only
2 parents 91a4de3 + 0ea2228 commit 922f1b0

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)