Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7e9bef

Browse files
committed
bug #19081 [YAML] Fixed parsing problem with nested DateTime lists (jkphl, xabbuh)
This PR was merged into the 3.1 branch. Discussion ---------- [YAML] Fixed parsing problem with nested DateTime lists | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19029 | License | MIT | Doc PR | The new handling for `DateTimeInterface` instances was introduced in Symfony 3.1. Commits ------- 0f47712 parse embedded mappings only if value is a string 4f13a76 [YAML] Fixed parsing problem with nested DateTime lists
2 parents 33636c7 + 0f47712 commit e7e9bef

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
@@ -397,7 +397,7 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
397397
$value = self::parseScalar($sequence, $flags, array(',', ']'), array('"', "'"), $i, true, $references);
398398

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,22 @@ public function getTimestampTests()
524524
);
525525
}
526526

527+
/**
528+
* @dataProvider getTimestampTests
529+
*/
530+
public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
531+
{
532+
$expected = new \DateTime($yaml);
533+
$expected->setTimeZone(new \DateTimeZone('UTC'));
534+
$expected->setDate($year, $month, $day);
535+
$expected->setTime($hour, $minute, $second);
536+
537+
$expectedNested = array('nested' => array($expected));
538+
$yamlNested = "{nested: [$yaml]}";
539+
540+
$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
541+
}
542+
527543
/**
528544
* @dataProvider getDateTimeDumpTests
529545
*/

0 commit comments

Comments
 (0)