Skip to content

[YAML] Fixed parsing problem with nested DateTime lists #19029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Yaml/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
$value = self::parseScalar($sequence, $flags, array(',', ']'), array('"', "'"), $i, true, $references);

// the value can be an array if a reference has been resolved to an array var
if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) {
if (!is_array($value) && !$value instanceof \DateTimeInterface && !$isQuoted && false !== strpos($value, ': ')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using !is_object() here instead? That would also cover the case when an unserialized object was returned before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might also do the job, of course, but I don't really overlook the consequences. Running strpos on an object will most likely fail in most of the situations, so it's probably reasonable, yes. But as I said, I don't overlook every aspect — are there any kinds of serializable objects allowed? — so I wanted to keep it as specific as possible. Feel free to loosen this in case is_object() doesn't break anything I don't see ...

// embedded mapping?
try {
$pos = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Yaml/Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,22 @@ public function getTimestampTests()
);
}

/**
* @dataProvider getTimestampTests
*/
public function testParseNestedTimestampListAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
{
$expected = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day);
$expected->setTime($hour, $minute, $second);

$expectedNested = array('nested' => array($expected));
$yamlNested = "{nested: [$yaml]}";

$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
}

/**
* @dataProvider getDateTimeDumpTests
*/
Expand Down