-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/IgnoreDummyAdditionalGetter.php
Outdated
Show resolved
Hide resolved
Thank you @astepin. |
@@ -100,6 +100,11 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata) | |||
continue; | |||
} | |||
|
|||
$getAccessor = preg_match('/^(get|)(.+)$/i', $method->name); |
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.
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)
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.
I've filed #47255 to fix this.
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.
I missed that. A copy paste error. Thanks @jsor for fixing
…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
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.