Skip to content

Commit

Permalink
Change RenameUpload filter use_upload_name option default to a safer …
Browse files Browse the repository at this point in the history
…setting
  • Loading branch information
cgmartin committed Jan 3, 2013
1 parent 898d2ef commit a911251
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
6 changes: 2 additions & 4 deletions library/Zend/Filter/File/RenameUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RenameUpload extends AbstractFilter
*/
protected $options = array(
'target' => null,
'use_upload_name' => true,
'use_upload_name' => false,
'overwrite' => false,
'randomize' => false,
);
Expand All @@ -42,8 +42,6 @@ public function __construct($targetOrOptions)
} else {
$this->setTarget($targetOrOptions);
}


}

/**
Expand Down Expand Up @@ -145,7 +143,7 @@ public function filter($value)
} else {
$uploadData = array(
'tmp_name' => $value,
'name' => $value,
'name' => $value,
);
$sourceFile = $value;
}
Expand Down
19 changes: 4 additions & 15 deletions tests/ZendTest/Filter/File/RenameUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function tearDown()
public function testThrowsExceptionWithNonUploadedFile()
{
$filter = new FileRenameUpload($this->_newFile);
$filter->setUseUploadName(false);
$this->assertEquals($this->_newFile, $filter->getTarget());
$this->assertEquals('falsefile', $filter('falsefile'));
$this->setExpectedException(
Expand Down Expand Up @@ -165,18 +164,18 @@ public function testOptions()
{
$filter = new FileRenameUpload($this->_newFile);
$this->assertEquals($this->_newFile, $filter->getTarget());
$this->assertTrue($filter->getUseUploadName());
$this->assertFalse($filter->getUseUploadName());
$this->assertFalse($filter->getOverwrite());
$this->assertFalse($filter->getRandomize());

$filter = new FileRenameUpload(array(
'target' => $this->_oldFile,
'use_upload_name' => false,
'use_upload_name' => true,
'overwrite' => true,
'randomize' => true,
));
$this->assertEquals($this->_oldFile, $filter->getTarget());
$this->assertFalse($filter->getUseUploadName());
$this->assertTrue($filter->getUseUploadName());
$this->assertTrue($filter->getOverwrite());
$this->assertTrue($filter->getRandomize());
}
Expand All @@ -189,7 +188,6 @@ public function testStringConstructorParam()
$this->setUpMockMoveUploadedFile();

$filter = new FileRenameUpload($this->_newFile);
$filter->setUseUploadName(false);
$this->assertEquals($this->_newFile, $filter->getTarget());
$this->assertEquals($this->_newFile, $filter($this->_oldFile));
$this->assertEquals('falsefile', $filter('falsefile'));
Expand Down Expand Up @@ -225,10 +223,7 @@ public function testArrayConstructorParam()
$this->setUpMockMoveUploadedFile();

$filter = new FileRenameUpload(array(
'target' => $this->_newFile,
'use_upload_name' => false,
'overwrite' => false,
'randomize' => false,
'target' => $this->_newFile,
));
$this->assertEquals($this->_newFile, $filter->getTarget());
$this->assertEquals($this->_newFile, $filter($this->_oldFile));
Expand All @@ -241,7 +236,6 @@ public function testArrayConstructorParam()
public function testConstructTruncatedTarget()
{
$filter = new FileRenameUpload('*');
$filter->setUseUploadName(false);
$this->assertEquals('*', $filter->getTarget());
$this->assertEquals($this->_oldFile, $filter($this->_oldFile));
$this->assertEquals('falsefile', $filter('falsefile'));
Expand All @@ -255,7 +249,6 @@ public function testTargetDirectory()
$this->setUpMockMoveUploadedFile();

$filter = new FileRenameUpload($this->_newDir);
$filter->setUseUploadName(false);
$this->assertEquals($this->_newDir, $filter->getTarget());
$this->assertEquals($this->_newDirFile, $filter($this->_oldFile));
$this->assertEquals('falsefile', $filter('falsefile'));
Expand All @@ -271,7 +264,6 @@ public function testOverwriteWithExistingFile()
$filter = new FileRenameUpload(array(
'target' => $this->_newFile,
'overwrite' => true,
'use_upload_name' => false,
));

copy($this->_oldFile, $this->_newFile);
Expand All @@ -290,7 +282,6 @@ public function testCannotOverwriteExistingFile()
$filter = new FileRenameUpload(array(
'target' => $this->_newFile,
'overwrite' => false,
'use_upload_name' => false,
));

copy($this->_oldFile, $this->_newFile);
Expand All @@ -313,7 +304,6 @@ public function testGetRandomizedFile()
$filter = new FileRenameUpload(array(
'target' => $this->_newFile,
'randomize' => true,
'use_upload_name' => false,
));

$this->assertEquals($this->_newFile, $filter->getTarget());
Expand All @@ -333,7 +323,6 @@ public function testGetRandomizedFileWithoutExtension()
$filter = new FileRenameUpload(array(
'target' => $fileNoExt,
'randomize' => true,
'use_upload_name' => false,
));

$this->assertEquals($fileNoExt, $filter->getTarget());
Expand Down

0 comments on commit a911251

Please sign in to comment.