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

Skip to content

Commit ce5a28a

Browse files
🐛 Gracefully handle invalid dates
1 parent 031dde7 commit ce5a28a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,13 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
716716
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
717717
return (float) str_replace('_', '', $scalar);
718718
case Parser::preg_match(self::getTimestampRegex(), $scalar):
719-
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
720-
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
719+
try {
720+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
721+
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
722+
} catch (\Exception $e) {
723+
// Some dates accepted by the regex are not valid dates
724+
return (string) $scalar;
725+
}
721726

722727
if (Yaml::PARSE_DATETIME & $flags) {
723728
return $time;

0 commit comments

Comments
 (0)