-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][Serializer] Add an ArgumentResolver to deserialize & validate user input #45628
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
Changes from 1 commit
da5e8a4
3012614
6000089
4bb2235
642c7d0
2368c7f
5905ae0
406f1eb
7f7500c
eae458f
1523617
5976a4b
ebeee98
8000 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,10 +54,10 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable | |
$context = array_merge($attribute->serializationContext, [ | ||
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true, | ||
]); | ||
$format = $attribute->format ?? $request->attributes->get('_format', 'json'); | ||
$format = $attribute->format ?? $request->getContentType() ?? 'json'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For security reasons, I suggest to throw an exception if the format isn't provided in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just use |
||
|
||
try { | ||
$input = $this->serializer->deserialize(data: $request->getContent(), type: $argument->getType(), format: $format, context: $context); | ||
$input = $this->serializer->deserialize($request->getContent(), $argument->getType(), $format, $context); | ||
} catch (PartialDenormalizationException $e) { | ||
if (null === $this->validator) { | ||
throw new UnprocessableEntityHttpException(message: $e->getMessage(), previous: $e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will show an empty message which is not useful. However, we can still normalize the |
||
|
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.
What about adding
AbstractObjectNormalizer::ALLOW_EXTRA_ATTRIBUTES => false
?