Skip to content

Commit be37e7f

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date [ExpressionLanguage] Improve test coverage [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent [Security] consistent singular/plural translation in Dutch reset the validation context after validating nested constraints do not duplicate directory separators fix handling empty data in ValueToDuplicatesTransformer [Validator] review latvian translations [Validator] Add Dutch translation for `WordCount` constraint allow more unicode characters in URL paths [String][EnglishInflector] Fix words ending in 'le', e.g., articles do not duplicate directory separators [Uid] Ensure UuidV1 is created in lowercase
2 parents 52903de + 62f96e1 commit be37e7f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Inline.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,13 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
709709
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
710710
return (float) str_replace('_', '', $scalar);
711711
case Parser::preg_match(self::getTimestampRegex(), $scalar):
712-
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
713-
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
712+
try {
713+
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
714+
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
715+
} catch (\Exception $e) {
716+
// Some dates accepted by the regex are not valid dates.
717+
throw new ParseException(\sprintf('The date "%s" could not be parsed as it is an invalid date.', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename, $e);
718+
}
714719

715720
if (Yaml::PARSE_DATETIME & $flags) {
716721
return $time;

Tests/InlineTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@ public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $
613613
$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
614614
}
615615

616+
public function testParseInvalidDate()
617+
{
618+
$this->expectException(ParseException::class);
619+
$this->expectExceptionMessageMatches('/^The date "2024-50-50" could not be parsed as it is an invalid date.*/');
620+
621+
Inline::parse('2024-50-50', Yaml::PARSE_DATETIME);
622+
}
623+
616624
/**
617625
* @dataProvider getDateTimeDumpTests
618626
*/

0 commit comments

Comments
 (0)