diff --git a/FileBag.php b/FileBag.php index 3c3612ef2..65242453c 100644 --- a/FileBag.php +++ b/FileBag.php @@ -113,6 +113,8 @@ protected function convertFileInformation($file) */ protected function fixPhpFilesArray($data) { + // Remove extra key added by PHP 8.1. + unset($data['full_path']); $keys = array_keys($data); sort($keys); diff --git a/Tests/FileBagTest.php b/Tests/FileBagTest.php index 7b33df471..b12621e7d 100644 --- a/Tests/FileBagTest.php +++ b/Tests/FileBagTest.php @@ -45,6 +45,23 @@ public function testShouldConvertsUploadedFiles() $this->assertEquals($file, $bag->get('file')); } + public function testShouldConvertsUploadedFilesPhp81() + { + $tmpFile = $this->createTempFile(); + $file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain'); + + $bag = new FileBag(['file' => [ + 'name' => basename($tmpFile), + 'full_path' => basename($tmpFile), + 'type' => 'text/plain', + 'tmp_name' => $tmpFile, + 'error' => 0, + 'size' => null, + ]]); + + $this->assertEquals($file, $bag->get('file')); + } + public function testShouldSetEmptyUploadedFilesToNull() { $bag = new FileBag(['file' => [