Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ce5a28a

Browse filesBrowse files
🐛 Gracefully handle invalid dates
1 parent 031dde7 commit ce5a28a
Copy full SHA for ce5a28a

File tree

1 file changed

+7
-2
lines changed
Filter options

1 file changed

+7
-2
lines changed

‎src/Symfony/Component/Yaml/Inline.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Inline.php
+7-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.