Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Ignore getter with required parameters (Fix #46592) #46958

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

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

astepin
Copy link
Contributor

@astepin astepin commented Jul 16, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #46592
License MIT
Doc PR na

If no Ignore annotation is used, the attributes for serialization are obtained using Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes.
There it is checked if the method has required parameters and if yes, the method is ignored.

However, if you use the Ignore annotation, the attributes are determined with a different method. Here I have adapted at least for get methods the behavior as it was before.

If someone serialized a class with Ignore annotations before, he got here \Symfony\Component\PropertyAccess\PropertyAccessor::readProperty an exception as written in ticket #46592. With this fix the methods are ignored and there is no exception anymore.

@carsonbot

This comment was marked as outdated.

@astepin astepin marked this pull request as ready for review July 16, 2022 21:51
@astepin astepin requested a review from dunglas as a code owner July 16, 2022 21:51
@carsonbot carsonbot added this to the 5.4 milestone Jul 16, 2022
@carsonbot

This comment was marked as outdated.

@fabpot
Copy link
Member

fabpot commented Jul 19, 2022

Thank you @astepin.

@fabpot fabpot merged commit c89721e into symfony:5.4 Jul 19, 2022
@astepin astepin deleted the fix_46592 branch July 19, 2022 15:37
@@ -100,6 +100,11 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
continue;
}

$getAccessor = preg_match('/^(get|)(.+)$/i', $method->name);
Copy link
Contributor

Choose a reason for hiding this comment

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

This regex looks "fishy": ignoring capturing groups (as matches are not used), it's equivalent to /^(get)?.+$/i i.e. just /^.+$/ i.e. will match any method (not only getters)

Copy link
Contributor

Choose a reason for hiding this comment

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

I've filed #47255 to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that. A copy paste error. Thanks @jsor for fixing

@fabpot fabpot mentioned this pull request Jul 29, 2022
This was referenced Jul 29, 2022
fabpot added a commit that referenced this pull request Aug 12, 2022
…sor)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix get accessor regex in AnnotationLoader

The pipe in the regex makes it match *all* methods.

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

This fixes a bug introduced in #46958. It was also discovered in the PR but after it got merged. See #46958 (comment).

Commits
-------

1132171 [Serializer] Fix get accessor regex in AnnotationLoader
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.

7 participants