Skip to content
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

Closed

Conversation

sidz
Copy link
Contributor

@sidz sidz commented Jun 1, 2021

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.

@nicolas-grekas
Copy link
Member

Please check tests as they're failing right now.

@sidz sidz force-pushed the do-not-allow-to-denormalize-string-with-spaces branch from 7f3cc19 to f6ab2bf Compare June 3, 2021 17:12
@sidz
Copy link
Contributor Author

sidz commented Jun 3, 2021

@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))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@sidz sidz Jun 3, 2021

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.

@nicolas-grekas
Copy link
Member

Thank you @sidz.

nicolas-grekas added a commit that referenced this pull request Jun 4, 2021
…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
@chalasr
Copy link
Member

chalasr commented Jun 4, 2021

Looks like something went wrong in the merge process. I'm closing the PR but no worries, the merge did happen 3524cf2.

@chalasr chalasr closed this Jun 4, 2021
@sidz sidz deleted the do-not-allow-to-denormalize-string-with-spaces branch June 4, 2021 12:50
@fabpot fabpot mentioned this pull request Jun 17, 2021
This was referenced Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants