Skip to content

Commit

Permalink
bug #50673 [HttpKernel] make RequestPayloadValueResolver::resolve()
Browse files Browse the repository at this point in the history
… throw on variadic argument (javaDeveloperKid)

This PR was merged into the 6.3 branch.

Discussion
----------

[HttpKernel] make `RequestPayloadValueResolver::resolve()` throw on variadic argument

| Q             | A
| ------------- | ---
| Branch?       | 6.3 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | yno <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #50668 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the latest branch.
 - For new features, provide some code snippets to help understand usage.
 - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
 - Never break backward compatibility (see https://symfony.com/bc).
-->

Commits
-------

1c27cf1 [HttpKernel] make RequestPayloadValueResolver:resolve() throw on variadic argument
  • Loading branch information
nicolas-grekas committed Jun 21, 2023
2 parents 8648df5 + 1c27cf1 commit ad04747
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -72,6 +72,10 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
return [];
}

if ($argument->isVariadic()) {
throw new \LogicException(sprintf('Mapping variadic argument "$%s" is not supported.', $argument->getName()));
}

$attribute->metadata = $argument;

return [$attribute];
Expand Down
Expand Up @@ -221,6 +221,22 @@ public function testRequestInputValidationPassed()
$this->assertEquals([$payload], $event->getArguments());
}

public function testItThrowsOnVariadicArgument()
{
$serializer = new Serializer();
$validator = $this->createMock(ValidatorInterface::class);
$resolver = new RequestPayloadValueResolver($serializer, $validator);

$argument = new ArgumentMetadata('variadic', RequestPayload::class, true, false, null, false, [
MapRequestPayload::class => new MapRequestPayload(),
]);
$request = Request::create('/', 'POST');

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Mapping variadic argument "$variadic" is not supported.');
$resolver->resolve($request, $argument);
}

/**
* @dataProvider provideMatchedFormatContext
*/
Expand Down

0 comments on commit ad04747

Please sign in to comment.