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

[HttpKernel] Fix variadic TypeError for #[MapUploadedFile] #54901

Open
wants to merge 1 commit into
base: 7.1
Choose a base branch
from

Conversation

DjordyKoert
Copy link

Q A
Branch? 7.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

This PR fixes a bug introduced in #49978 where using #[MapUploadedFile] with a variadic argument causes a TypeError:

class MyController
{
    public function __invoke(
        #[MapUploadedFile] UploadedFile ...$documents,
    ): Response {
    }
}
Argument #1 must be of type Symfony\\Component\\HttpFoundation\\File\\UploadedFile, array given

(Bug fix taken from #54817)

@carsonbot carsonbot added this to the 7.1 milestone May 13, 2024
@DjordyKoert DjordyKoert changed the title [HttpKernel] Fix variadic TypeError for MapUploadedFile [HttpKernel] Fix variadic TypeError for #[MapUploadedFile] May 13, 2024
@DjordyKoert
Copy link
Author

Failing tests seem unrelated

@@ -170,7 +170,11 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
};
}

$arguments[$i] = $payload;
if ($argument->metadata->isVariadic() && \is_array($payload)) {
Copy link
Member

Choose a reason for hiding this comment

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

if the payload is not an array, we should throw a 422 instead, don't you think?
we should also use array_is_list so that we don't map to named arguments by mistake

@@ -170,7 +170,11 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
};
}

$arguments[$i] = $payload;
if ($argument->metadata->isVariadic() && \is_array($payload)) {
array_splice($arguments, $i, 1, $payload);
Copy link
Member

Choose a reason for hiding this comment

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

could we use array_merge instead? that might be more readable

@nicolas-grekas nicolas-grekas changed the base branch from 7.2 to 7.1 May 21, 2024 07:51
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

3 participants