Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge 3c15893 into 126aaa7
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 17, 2018
2 parents 126aaa7 + 3c15893 commit be2d653
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/File/RenameUpload.php
Expand Up @@ -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];
}
Expand Down
49 changes: 49 additions & 0 deletions test/File/RenameUploadTest.php
Expand Up @@ -412,4 +412,53 @@ public function testReturnUnfiltered($input)

$this->assertEquals($input, $filter($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->sourceFile,
'name' => basename($this->targetFile),
],
$filter([
'tmp_name' => $this->sourceFile,
'name' => basename($this->targetFile),
])
);
}
}

0 comments on commit be2d653

Please sign in to comment.