Skip to content

Commit 92614bb

Browse files
Merge branch '3.3' into 3.4
* 3.3: [HttpKernel] DebugHandlersListener should always replace the existing exception handler fix the Composer API being used [Debug] Always decorate existing exception handlers to deal with fatal errors Enableable ArrayNodeDefinition is disabled for empty configuration Fixing a bug where the dump() function depended on bundle ordering [Cache] Fix handling of apcu_fetch() edgy behavior Add nn (Norwegian Nynorsk) translation files, and improve existing file Problem in phar see mergerequest #25579 [Form] Disallow transform dates beyond the year 9999 Copied NO language files to the new NB locale. [Serializer] DateTimeNormalizer handling of null and empty values (returning null or empty instead of new object) [Console] Improve phpdoc on StyleInterface::ask()
2 parents 2e928e6 + 49a429e commit 92614bb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Normalizer/DateTimeNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public function denormalize($data, $class, $format = null, array $context = arra
8383
$dateTimeFormat = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : null;
8484
$timezone = $this->getTimezone($context);
8585

86+
if ('' === $data || null === $data) {
87+
throw new UnexpectedValueException('The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid DateTime string.');
88+
}
89+
8690
if (null !== $dateTimeFormat) {
8791
if (null === $timezone && PHP_VERSION_ID < 70000) {
8892
// https://bugs.php.net/bug.php?id=68669

Tests/Normalizer/DateTimeNormalizerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ public function testDenormalizeInvalidDataThrowsException()
167167
$this->normalizer->denormalize('invalid date', \DateTimeInterface::class);
168168
}
169169

170+
/**
171+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
172+
* @expectedExceptionMessage The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid DateTime string.
173+
*/
174+
public function testDenormalizeNullThrowsException()
175+
{
176+
$this->normalizer->denormalize(null, \DateTimeInterface::class);
177+
}
178+
179+
/**
180+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
181+
* @expectedExceptionMessage The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid DateTime string.
182+
*/
183+
public function testDenormalizeEmptyStringThrowsException()
184+
{
185+
$this->normalizer->denormalize('', \DateTimeInterface::class);
186+
}
187+
170188
/**
171189
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
172190
*/

0 commit comments

Comments
 (0)