Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

[BUG] This fix allows the upload of same filenames in input type file #652

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions library/Zend/File/Transfer/Adapter/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ protected function _prepareFiles()

$this->_files[$form]['name'] = $form;
foreach($this->_files[$form]['multifiles'] as $key => $value) {
if ($this->_files[$value]['tmp_name'] !== '') {
$this->_files[$value]['name'] = basename($this->_files[$value]['tmp_name']) . '_' . $this->_files[$value]['name'];
}
$this->_files[$value]['options'] = $this->_options;
$this->_files[$value]['validated'] = false;
$this->_files[$value]['received'] = false;
Expand All @@ -464,6 +467,9 @@ protected function _prepareFiles()
}
} else {
$this->_files[$form] = $content;
if ($this->_files[$form]['tmp_name'] !== '') {
$this->_files[$form]['name'] = basename($this->_files[$form]['tmp_name']) . '_' . $this->_files[$form]['name'];
}
$this->_files[$form]['options'] = $this->_options;
$this->_files[$form]['validated'] = false;
$this->_files[$form]['received'] = false;
Expand Down
66 changes: 53 additions & 13 deletions tests/Zend/File/Transfer/Adapter/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public function setUp()
{
$_FILES = array(
'txt' => array(
'name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'error' => 0));
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0
)
);
$this->adapter = new Zend_File_Transfer_Adapter_HttpTest_MockAdapter();
}

Expand All @@ -87,7 +89,7 @@ public function tearDown()
public function testEmptyAdapter()
{
$files = $this->adapter->getFileName();
$this->assertContains('test.txt', $files);
$this->assertContains('php0zgByO_test.txt', $files);
}

public function testAutoSetUploadValidator()
Expand Down Expand Up @@ -194,37 +196,75 @@ public function testReceiveWithRenameFilterButWithoutDirectory()
$this->assertTrue($this->adapter->receive());
}


public function testMultiFiles()
{
$_FILES = array(
'txt' => array(
'name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0
),
'exe' => array(
'name' => array(
0 => 'file1.exe',
1 => 'file2.exe'),
'type' => array(
0 => 'plain/text',
1 => 'plain/text'),
'size' => array(
0 => 8,
1 => 8),
'tmp_name' => array(
0 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpqBXGTg',
1 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpZqRDQF'),
'error' => array(
0 => 0,
1 => 0)));
$adapter = new Zend_File_Transfer_Adapter_HttpTest_MockAdapter();
$adapter->setOptions(array('ignoreNoFile' => true));
$this->assertTrue($adapter->receive('exe'));
$this->assertEquals(
array('exe_0_' => 'phpqBXGTg_file1.exe',
'exe_1_' => 'phpZqRDQF_file2.exe'),
$adapter->getFileName('exe', false));
}


public function testMultiFilesSameName()
{
$_FILES = array(
'txt' => array(
'name' => 'test.txt',
'type' => 'plain/text',
'size' => 8,
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test.txt',
'error' => 0),
'tmp_name' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'php0zgByO',
'error' => 0
),
'exe' => array(
'name' => array(
0 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
1 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'),
0 => 'file.exe',
1 => 'file.exe'),
'type' => array(
0 => 'plain/text',
1 => 'plain/text'),
'size' => array(
0 => 8,
1 => 8),
'tmp_name' => array(
0 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
1 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'),
0 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpOOwDDc',
1 => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'phpDlIxkx'),
'error' => array(
0 => 0,
1 => 0)));
$adapter = new Zend_File_Transfer_Adapter_HttpTest_MockAdapter();
$adapter->setOptions(array('ignoreNoFile' => true));
$this->assertTrue($adapter->receive('exe'));
$this->assertEquals(
array('exe_0_' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file1.txt',
'exe_1_' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'file2.txt'),
array('exe_0_' => 'phpOOwDDc_file.exe',
'exe_1_' => 'phpDlIxkx_file.exe'),
$adapter->getFileName('exe', false));
}

Expand Down
1 change: 0 additions & 1 deletion tests/Zend/File/Transfer/Adapter/_files/file2.txt

This file was deleted.

1 change: 1 addition & 0 deletions tests/Zend/File/Transfer/Adapter/_files/phpDlIxkx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions tests/Zend/File/Transfer/Adapter/_files/phpOOwDDc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions tests/Zend/File/Transfer/Adapter/_files/phpZqRDQF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
1 change: 1 addition & 0 deletions tests/Zend/File/Transfer/Adapter/_files/phpqBXGTg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testfile
2 changes: 1 addition & 1 deletion tests/Zend/File/Transfer/Adapter/_files/test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
testfile
testfile