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

Commit

Permalink
Merge 36b3345 into 126aaa7
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Dec 17, 2018
2 parents 126aaa7 + 36b3345 commit 8b2ec88
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#79](https://github.com/zendframework/zend-filter/pull/79) Fix regression bug introduced in 2.9.0 when using
`Zend\Filter\File\RenameUpload` via the traditional SAPI

## 2.9.0 - 2018-12-12

Expand Down
8 changes: 3 additions & 5 deletions src/File/RenameUpload.php
Original file line number Diff line number Diff line change
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
50 changes: 50 additions & 0 deletions test/File/RenameUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,54 @@ 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` cache path
$this->assertEquals($sapiTarget, $filter($sapiSource));
$this->assertEquals($sapiTarget, $filter($sapiSource));
}

/**
* @see https://github.com/zendframework/zend-filter/issues/76
* @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 8b2ec88

Please sign in to comment.