Skip to content

[YAML] DateTime parsing with PARSE_DATETIME causes fatal error #18897

Closed
@jkphl

Description

@jkphl

With reference to #18859, using the new PARSE_DATETIME flag causes a fatal error when parsing an ISO 8601 date:

var_dump(Yaml::parse("date: 2002-12-14", Yaml::PARSE_DATETIME));

results in:

PHP Warning:  strpos() expects parameter 1 to be string, object given in [...]\symfony\yaml\Parser.php on line 542
PHP Fatal error:  Uncaught exception 'Symfony\Component\Yaml\Exception\ParseException' with message 'A colon cannot be used in an unquoted mapping value at line 1 (near "date: 2002-12-14").' in [...]\symfony\yaml\Parser.php:543
Stack trace:

Quoting the date doesn't yield an error but creates no DateTime object either:

print_r(Yaml::parse("date: '2002-12-14'", Yaml::PARSE_DATETIME));

Array
(
    [date] => 2002-12-14
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions