Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
derrabus committed Aug 12, 2024
2 parents 52903de + 62f96e1 commit be37e7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,13 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
return (float) str_replace('_', '', $scalar);
case Parser::preg_match(self::getTimestampRegex(), $scalar):
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
try {
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
$time = new \DateTimeImmutable($scalar, new \DateTimeZone('UTC'));
} catch (\Exception $e) {
// Some dates accepted by the regex are not valid dates.
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);
}

if (Yaml::PARSE_DATETIME & $flags) {
return $time;
Expand Down
8 changes: 8 additions & 0 deletions Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ public function testParseNestedTimestampListAsDateTimeObject(string $yaml, int $
$this->assertEquals($expectedNested, Inline::parse($yamlNested, Yaml::PARSE_DATETIME));
}

public function testParseInvalidDate()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessageMatches('/^The date "2024-50-50" could not be parsed as it is an invalid date.*/');

Inline::parse('2024-50-50', Yaml::PARSE_DATETIME);
}

/**
* @dataProvider getDateTimeDumpTests
*/
Expand Down

0 comments on commit be37e7f

Please sign in to comment.