-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Do not allow to denormalize string with spaces only to valid a DateTime object #41491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serializer] Do not allow to denormalize string with spaces only to valid a DateTime object #41491
Conversation
src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php
Outdated
Show resolved
Hide resolved
Please check tests as they're failing right now. |
7f3cc19
to
f6ab2bf
Compare
@nicolas-grekas done |
@@ -97,7 +97,7 @@ public function denormalize($data, $type, $format = null, array $context = []) | |||
$dateTimeFormat = $context[self::FORMAT_KEY] ?? null; | |||
$timezone = $this->getTimezone($context); | |||
|
|||
if ('' === $data || null === $data) { | |||
if (null === $data || (\is_string($data) && '' === trim($data))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well this change a lot but exception message says:
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.
Thank you @sidz. |
…s only to valid a DateTime object (sidz) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Serializer] Do not allow to denormalize string with spaces only to valid a DateTime object | Q | A | ------------- | --- | Branch? |4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT This PR fixes an issue when `$data` variable contains only spaces. In this case DateTimeNormalizer creates a DateTime object. Commits ------- 21c0829 [Serializer] Do not allow to denormalize string with spaces only to valid a DateTime object
Looks like something went wrong in the merge process. I'm closing the PR but no worries, the merge did happen 3524cf2. |
This PR fixes an issue when
$data
variable contains only spaces. In this case DateTimeNormalizer creates a DateTime object.