Skip to content

Commit ca1000f

Browse files
committed
driver: detect array file param gracefully
1 parent d2d8426 commit ca1000f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Driver/BaseHandler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Http\Request;
1010
use Symfony\Component\HttpFoundation\Response;
1111
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
12+
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
1213

1314
abstract class BaseHandler
1415
{
@@ -62,17 +63,21 @@ protected function triggerFileUploadedEvent($disk, $path, Closure $fileUploaded
6263
/**
6364
* Validate an uploaded file. An exception is thrown when it is invalid.
6465
*
65-
* @param \Illuminate\Http\UploadedFile|null $file
66+
* @param \Illuminate\Http\UploadedFile|array|null $file
6667
*
6768
* @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException when given file is null.
6869
* @throws \CodingSocks\UploadHandler\Exception\InternalServerErrorHttpException when given file is invalid.
6970
*/
70-
protected function validateUploadedFile(UploadedFile $file = null): void
71+
protected function validateUploadedFile($file): void
7172
{
7273
if (null === $file) {
7374
throw new BadRequestHttpException('File not found in request body');
7475
}
7576

77+
if (is_array($file)) {
78+
throw new UnprocessableEntityHttpException('File parameter cannot be an array');
79+
}
80+
7681
if (! $file->isValid()) {
7782
throw new InternalServerErrorHttpException($file->getErrorMessage());
7883
}

0 commit comments

Comments
 (0)