Issues

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

Issue Type: Bug Created: 2011-09-06T00:11:10.000+0000 Last Updated: 2012-03-10T03:15:51.000+0000 Status: Open Fix version(s): Reporter: Karol Malinowski (malin) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

  • zf-crteam-review

Related issues: Attachments: - ZF-11723.patch

Description

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

Comments

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-06T16:14:28.000+0000

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.

Posted by Adam Lundrigan (adamlundrigan) on 2012-03-10T03:14:28.000+0000

Test:

<pre class="highlight">
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:

<pre class="highlight">
1) Zend_File_Transfer_Adapter_AbstractTest::testCanReceiveFileHavingNameZero
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-/tmp/0
+Array

Fix:

<pre class="highlight">

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;
             }
 

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts