From ec209926a52a0f77476c31eb0fe85e81b5a3d4ea Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 17 Dec 2018 12:13:01 +0100 Subject: [PATCH 1/2] Prove 2.9 BC break --- test/File/RenameUploadTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/File/RenameUploadTest.php b/test/File/RenameUploadTest.php index bf462611..1a70cbaf 100644 --- a/test/File/RenameUploadTest.php +++ b/test/File/RenameUploadTest.php @@ -412,4 +412,30 @@ public function testReturnUnfiltered($input) $this->assertEquals($input, $filter($input)); } + + /** + * @see https://github.com/zendframework/zend-filter/issues/77 + */ + public function testBackwordCompatibilityBreakFromRelease280ToRelease290() + { + $filter = new RenameUploadMock($this->targetPath); + + $this->assertEquals( + [ + 'tmp_name' => $this->targetPathFile, + 'name' => basename($this->targetFile), + 'type' => 'text/plain', + 'error' => \UPLOAD_ERR_OK, + 'size' => 123, + ], + // Emulate the output of \Zend\Http\Request::getFiles()->toArray() + $filter([ + 'tmp_name' => $this->sourceFile, + 'name' => basename($this->targetFile), + 'type' => 'text/plain', + 'error' => \UPLOAD_ERR_OK, + 'size' => 123, + ]) + ); + } } From 3c15893b3c6a61defc74f12ffe1b40f91807a3d2 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 17 Dec 2018 12:27:08 +0100 Subject: [PATCH 2/2] Fix --- src/File/RenameUpload.php | 8 +++---- test/File/RenameUploadTest.php | 39 +++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/File/RenameUpload.php b/src/File/RenameUpload.php index 615bd480..6ed19cc4 100644 --- a/src/File/RenameUpload.php +++ b/src/File/RenameUpload.php @@ -373,16 +373,14 @@ private function filterSapiUploadedFile(array $fileData) $targetFile = $this->getFinalTarget($sourceFile, $clientFilename); if ($sourceFile === $targetFile || ! file_exists($sourceFile)) { - return $value; + return $fileData; } $this->checkFileExists($targetFile); $this->moveUploadedFile($sourceFile, $targetFile); - $this->alreadyFiltered[$sourceFile] = [ - 'tmp_name' => $clientFilename, - 'name' => $targetFile, - ]; + $this->alreadyFiltered[$sourceFile] = $fileData; + $this->alreadyFiltered[$sourceFile]['tmp_name'] = $targetFile; return $this->alreadyFiltered[$sourceFile]; } diff --git a/test/File/RenameUploadTest.php b/test/File/RenameUploadTest.php index 1a70cbaf..7f88c240 100644 --- a/test/File/RenameUploadTest.php +++ b/test/File/RenameUploadTest.php @@ -415,26 +415,49 @@ public function testReturnUnfiltered($input) /** * @see https://github.com/zendframework/zend-filter/issues/77 + * @return void */ public function testBackwordCompatibilityBreakFromRelease280ToRelease290() { $filter = new RenameUploadMock($this->targetPath); + // Emulate the output of \Zend\Http\Request::getFiles()->toArray() + $sapiSource = [ + 'tmp_name' => $this->sourceFile, + 'name' => basename($this->targetFile), + 'type' => 'text/plain', + 'error' => \UPLOAD_ERR_OK, + 'size' => 123, + ]; + + $sapiTarget = [ + 'tmp_name' => $this->targetPathFile, + 'name' => basename($this->targetFile), + 'type' => 'text/plain', + 'error' => \UPLOAD_ERR_OK, + 'size' => 123, + ]; + + // Check the result twice for the `alreadyFiltered` path + $this->assertEquals($sapiTarget, $filter($sapiSource)); + $this->assertEquals($sapiTarget, $filter($sapiSource)); + } + + /** + * @return void + */ + public function testTargetSameAsSource() + { + $filter = new RenameUploadMock(); + $this->assertEquals( [ - 'tmp_name' => $this->targetPathFile, + 'tmp_name' => $this->sourceFile, 'name' => basename($this->targetFile), - 'type' => 'text/plain', - 'error' => \UPLOAD_ERR_OK, - 'size' => 123, ], - // Emulate the output of \Zend\Http\Request::getFiles()->toArray() $filter([ 'tmp_name' => $this->sourceFile, 'name' => basename($this->targetFile), - 'type' => 'text/plain', - 'error' => \UPLOAD_ERR_OK, - 'size' => 123, ]) ); }