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

Commit 10374ab

Browse files
committed
Merge branch 'hotfix/79' into develop
Forward port #79 Conflicts: CHANGELOG.md
2 parents 06d76ea + 1c3e6d0 commit 10374ab

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file, in reverse
2424

2525
- Nothing.
2626

27-
## 2.9.1 - TBD
27+
## 2.9.1 - 2018-12-17
2828

2929
### Added
3030

@@ -44,7 +44,8 @@ All notable changes to this project will be documented in this file, in reverse
4444

4545
### Fixed
4646

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

4950
## 2.9.0 - 2018-12-12
5051

src/File/RenameUpload.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,14 @@ private function filterSapiUploadedFile(array $fileData)
373373

374374
$targetFile = $this->getFinalTarget($sourceFile, $clientFilename);
375375
if ($sourceFile === $targetFile || ! file_exists($sourceFile)) {
376-
return $value;
376+
return $fileData;
377377
}
378378

379379
$this->checkFileExists($targetFile);
380380
$this->moveUploadedFile($sourceFile, $targetFile);
381381

382-
$this->alreadyFiltered[$sourceFile] = [
383-
'tmp_name' => $clientFilename,
384-
'name' => $targetFile,
385-
];
382+
$this->alreadyFiltered[$sourceFile] = $fileData;
383+
$this->alreadyFiltered[$sourceFile]['tmp_name'] = $targetFile;
386384

387385
return $this->alreadyFiltered[$sourceFile];
388386
}

test/File/RenameUploadTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,50 @@ public function testReturnUnfiltered($input)
412412

413413
$this->assertEquals($input, $filter($input));
414414
}
415+
416+
/**
417+
* @see https://github.com/zendframework/zend-filter/issues/77
418+
* @return void
419+
*/
420+
public function testCachesResultsOfFilteringSAPIUploads()
421+
{
422+
$filter = new RenameUploadMock($this->targetPath);
423+
424+
// Emulate the output of \Zend\Http\Request::getFiles()->toArray()
425+
$sapiSource = [
426+
'tmp_name' => $this->sourceFile,
427+
'name' => basename($this->targetFile),
428+
'type' => 'text/plain',
429+
'error' => \UPLOAD_ERR_OK,
430+
'size' => 123,
431+
];
432+
433+
$sapiTarget = [
434+
'tmp_name' => $this->targetPathFile,
435+
'name' => basename($this->targetFile),
436+
'type' => 'text/plain',
437+
'error' => \UPLOAD_ERR_OK,
438+
'size' => 123,
439+
];
440+
441+
// Check the result twice for the `alreadyFiltered` cache path
442+
$this->assertEquals($sapiTarget, $filter($sapiSource));
443+
$this->assertEquals($sapiTarget, $filter($sapiSource));
444+
}
445+
446+
/**
447+
* @see https://github.com/zendframework/zend-filter/issues/76
448+
* @return void
449+
*/
450+
public function testFilterReturnsFileDataVerbatimUnderSAPIWhenNameAndTmpNameDiffer()
451+
{
452+
$filter = new RenameUploadMock();
453+
454+
$source = [
455+
'tmp_name' => $this->sourceFile,
456+
'name' => basename($this->targetFile),
457+
];
458+
459+
$this->assertEquals($source, $filter($source));
460+
}
415461
}

0 commit comments

Comments
 (0)