Issues

ZF-10738: Zend_Validate_File_Upload not E_NOTICE compliant

Issue Type: Bug Created: 2010-11-24T05:07:33.000+0000 Last Updated: 2011-07-26T17:52:00.000+0000 Status: Resolved Fix version(s): - 1.11.2 (30/Dec/10)

  • Next Major Release ()

Reporter: Kevin Schroeder (kschroeder) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate_File

Related issues: Attachments: - ZF-10738.patch

Description

Zend_Validate_File_Upload may throw E_Notice warnings during validation.

public function isValid($value, $file = null)
{
    $this->_messages = null;
    if (array_key_exists($value, $this->_files)) {
        $files[$value] = $this->_files[$value];
    } else {
        foreach ($this->_files as $file => $content) {
            if (isset($content['name']) && ($content['name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }

            if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }
        }
    }

Should be

public function isValid($value, $file = null)
{
    $this->_messages = null;

if (is_array($this->_files) && array_key_exists($value, $this->_files)) { $files[$value] = $this->_files[$value]; } else { foreach ($this->_files as $file => $content) { if (isset($content['name']) && ($content['name'] === $value)) { $files[$file] = $this->_files[$file]; }

            if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
                $files[$file] = $this->_files[$file];
            }
        }
    }

Comments

Posted by Kevin Schroeder (kschroeder) on 2010-11-24T05:11:39.000+0000

Dittos for public function setFiles($files = array()). The foreach loop assumes that $this->_files will be an array when, for some stupid reason, on my machine it is not.

Posted by Adam Lundrigan (adamlundrigan) on 2010-12-19T18:30:56.000+0000

I've added a test to Zend_Validate_File_UploadTest which reproduces your issue. Patch is attached.

Posted by Adam Lundrigan (adamlundrigan) on 2010-12-19T18:44:07.000+0000

I have attached a combined test+fix path for this issue.

Posted by Marc Hodgins (mjh_ca) on 2010-12-20T00:39:57.000+0000

Thanks for the patch and test Adam. Applied modified patch to trunk r23569 and merged to release branch 1.11 in r23570. It is cleaner to ensure that setFiles() always leaves the internal _files property as an array instead of adding the is_array tests in various places.

Posted by BenoƮt Durand (intiilapa) on 2011-02-03T11:14:28.000+0000

Why this issue is reopened?

Posted by Thomas Weidner (thomas) on 2011-07-26T17:52:00.000+0000

Fixed in ZF2 with GH-264

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