issue with php8.1 and new full_path key found in $_FILES, fixes #295

This commit is contained in:
Milos Stojanovic
2022-01-13 11:25:05 +01:00
parent d3b23cdc95
commit c158aa37aa
2 changed files with 36 additions and 1 deletions

View File

@@ -63,10 +63,20 @@ class UploadController
$total_size = (int) $request->input('resumableTotalSize'); $total_size = (int) $request->input('resumableTotalSize');
$identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier')); $identifier = (string) preg_replace('/[^0-9a-zA-Z_]/', '', (string) $request->input('resumableIdentifier'));
$file = $request->files->get('file'); $filebag = $request->files;
$file = $filebag->get('file');
$overwrite_on_upload = (bool) $this->config->get('overwrite_on_upload', false); $overwrite_on_upload = (bool) $this->config->get('overwrite_on_upload', false);
// php 8.1 fix
// remove new key 'full_path' so it can preserve compatibility with symfony FileBag
// see https://php.watch/versions/8.1/$_FILES-full-path
if ($file && is_array($file) && array_key_exists('full_path', $file)) {
unset($file['full_path']);
$filebag->set('file', $file);
$file = $filebag->get('file');
}
if (! $file || ! $file->isValid() || $file->getSize() > $this->config->get('frontend_config.upload_max_size')) { if (! $file || ! $file->isValid() || $file->getSize() > $this->config->get('frontend_config.upload_max_size')) {
return $response->json('Bad file', 422); return $response->json('Bad file', 422);
} }

View File

@@ -156,6 +156,31 @@ class UploadTest extends TestCase
]); ]);
} }
public function testUploadInvalidFile()
{
$this->signIn('john@example.com', 'john123');
$file = [
'tmp_name' => TEST_FILE,
'full_path' => 'something', // new in php 8.1
'name' => 'something',
'type' => 'application/octet-stream',
'size' => 12345,
'error' => 0,
];
$files = ['file' => $file];
$data = [];
$this->sendRequest('GET', '/upload', $data, $files);
$this->assertStatus(204);
$this->sendRequest('POST', '/upload', $data, $files);
$this->assertStatus(422);
}
public function testUploadFileBiggerThanAllowed() public function testUploadFileBiggerThanAllowed()
{ {
$this->signIn('john@example.com', 'john123'); $this->signIn('john@example.com', 'john123');