Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 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
  ...
  • Loading branch information
derrabus committed Aug 12, 2024
2 parents fa34c77 + be37e7f commit 92e080b
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 @@ -716,8 +716,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 @@ -620,6 +620,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 92e080b

Please sign in to comment.