8000 [YAML] Fixed parsing problem with nested DateTime lists · symfony/symfony@52384cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 52384cf

Browse files
jkphlfabpot
authored andcommitted
[YAML] Fixed parsing problem with nested DateTime lists
1 parent e188cd7 commit 52384cf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
398398
$value = self::parseScalar($sequence, $flags, array(',', ']'), array('"', "'"), $i, true, $references);
399399

400400
// the value can be an array if a reference has been resolved to an array var
401-
if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) {
401+
if (!is_array($value) && !$value instanceof \DateTimeInterface && !$isQuoted && false !== strpos($value, ': ')) {
402402
// embedded mapping?
403403
try {
404404
$pos = 0;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,22 @@ public function getTimestampTests()
548548
);
549549
}
550550

551+
/**
552+
* @dataProvider getTimestampTests
553+
*/
554+
public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
555+
{
556+
$expected = new \DateTime($yaml);
557+
$expected->setTimeZone(new \DateTimeZone('UTC'));
558+
$expected->setDate($year, $month, $day);
559+
$expected->setTime($hour, $minute, $second);
560+
561+
$expectedNested = array('nested' => array($expected));
562+
$yamlNested = "{nested: [$yaml]}";
563+
564+
$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
565+
}
566+
551567
/**
552568
* @dataProvider getDateTimeDumpTests
553569
*/

0 commit comments

Comments
 (0)
0