Skip to content

Commit 92e080b

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: (23 commits) fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date fix permitted data type of the default choice [ExpressionLanguage] Improve test coverage Fix invalid phpdoc in ContainerBuilder [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 fix compatibility with redis extension 6.0.3+ synchronize unsupported scheme tests [String] Fixed Quorum plural, that was inflected to be only "Quora" and never "Quorums" Fix symfony/kaz-info-teh-notifier package [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 ...
2 parents fa34c77 + be37e7f commit 92e080b

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
@@ -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+
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);
725+
}
721726

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

Tests/InlineTest.php

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

623+
public function testParseInvalidDate()
624+
{
625+
$this->expectException(ParseException::class);
626+
$this->expectExceptionMessageMatches('/^The date "2024-50-50" could not be parsed as it is an invalid date.*/');
627+
628+
Inline::parse('2024-50-50', Yaml::PARSE_DATETIME);
629+
}
630+
623631
/**
624632
* @dataProvider getDateTimeDumpTests
625633
*/

0 commit comments

Comments
 (0)