Issues

ZF-11723: Zend_File_Transfer::getFileName() returns empty array when uploading file with name "0"

Description

Zend_File_Transfer::getFileName() returns empty array when uploading file with name "0"

Comments

This happens because {{empty}} is used in {{Zend_File_Transfer_Adapter_Abstract}} on line 949 to determine if a filename was provided. Since PHP considers the zero string (ie: '0') to be "empty", it skips the file.

Test:


Index: tests/Zend/File/Transfer/Adapter/AbstractTest.php
===================================================================
--- tests/Zend/File/Transfer/Adapter/AbstractTest.php   (revision 24672)
+++ tests/Zend/File/Transfer/Adapter/AbstractTest.php   (working copy)
@@ -856,6 +856,17 @@
                 'detectInfos' => false))
             , $this->adapter->getOptions('foo'));
     }
+
+    /**
+     * @group ZF-11723
+     */
+    public function testCanReceiveFileHavingNameZero()
+    {
+        $adapter = new ZF11723_MockAdapter();
+        $adapter->setDestination('/tmp');
+        $this->assertTrue($adapter->isValid('foo'));
+        $this->assertEquals('/tmp/0', $adapter->getFileName());
+    }
 }
 
 class Zend_File_Transfer_Adapter_AbstractTest_MockAdapter extends Zend_File_Transfer_Adapter_Abstract
@@ -988,6 +999,30 @@
     }
 }
 
+/**
+ * @see ZF-11723
+ */
+class ZF11723_MockAdapter extends Zend_File_Transfer_Adapter_AbstractTest_MockAdapter
+{
+    public function __construct()
+    {
+        parent::__construct();
+        $this->_files = array(
+            'foo' => array(
+                'name'      => '0',
+                'type'      => 'image/jpeg',
+                'size'      => 126976,
+                'tmp_name'  => '/tmp/489127ba5c89c',
+                'options'   => array('ignoreNoFile' => false, 'useByteString' => true, 'detectInfos' => true),
+                'validated' => false,
+                'received'  => false,
+                'filtered'  => false,
+            ),
+        );
+    }
+}
+
+
 // Call Zend_File_Transfer_Adapter_AbstractTest::main() if this source file is executed directly.
 if (PHPUnit_MAIN_METHOD == "Zend_File_Transfer_Adapter_AbstractTest::main") {
     Zend_File_Transfer_Adapter_AbstractTest::main();

Result:


1) Zend_File_Transfer_Adapter_AbstractTest::testCanReceiveFileHavingNameZero
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-/tmp/0
+Array

Fix:



Index: library/Zend/File/Transfer/Adapter/Abstract.php
===================================================================
--- library/Zend/File/Transfer/Adapter/Abstract.php (revision 24672)
+++ library/Zend/File/Transfer/Adapter/Abstract.php (working copy)
@@ -946,7 +946,7 @@
         $result    = array();
         $directory = "";
         foreach($files as $file) {
-            if (empty($this->_files[$file]['name'])) {
+            if (trim($this->_files[$file]['name']) == '') {
                 continue;
             }