ZF-4386: Issue with ignoreNoFile in Zend_File_Transfer_Adapter_Abstract

Description

I discovered an issue with the ignoreNoFile option in the isValid() function in Zend_File_Transfer_Adapter_Abstract. The current problematic code ( latest trunk ) looks like this:


if ($this->_options['ignoreNoFile'] and (isset($fileerrors['fileUploadErrorNoFile']))) {
     unset($fileerrors['fileUploadErrorNoFile']);
}
if (($class === 'Zend_Validate_File_Upload') and (count($fileerrors) > 0)) {
    break;
}

From what i understand, the validation chain will be stopped if there was an error in the Upload validator. In case i use the ignoreNoFile option and i submit the form without uploading a file, all further validation after the Upload validator should be skipped.

With the current code, this is never happen, because the fileUploadErrorNoFile entry in the errors array will be removed earlier. To fix this, the code could be changed to this:


// error in the upload validator so stop validating
if (($class === 'Zend_Validate_File_Upload') and (count($fileerrors) > 0)) {
    // file element is not required and no file was uploaded so remove the error message 
    if ($this->_options['ignoreNoFile'] and (isset($fileerrors['fileUploadErrorNoFile']))) {
         unset($fileerrors['fileUploadErrorNoFile']); 
    }
    break;
}

Comments

Your change brakes option for other adapters than HTTP. Please give code for reproduction.

small test application

Added a small test application. I also made some notes about issue ZF-4347, which can be tested with this app, too.

Great demo app... Thanks ( I hope every commiter would be able to add such ;-) )

But when I submit the form without any file set, it returns to me "FORM VALID".

Maybe your repository is not up to date or broken ? Simply try to update to actual trunk.

Closing issue due to non-response

So i made a fresh export from the trunk and you are right, submitting without any file set works as intended.

However i still have problems with the validators and multiple file elements. I dont get the messages i should get, so will investigate a bit further. Should i open a new issue for this then?

When the issue is related to ignoreNoFile feel free to reopen this one. If you are getting a different issue, then please create a new one.

Issues should always be related to a single problem.

Wasn't sure if I should create a new ticket or comment on this one, but the check for ignoreNoFile is still flawed in 1.6.2

I had an issue where move_uploaded_file was failing and the specific file element was set to required. As a result, receive should be returning a value of false. However, the following line caused the error from move_uploaded_file to be skipped inside of the receive method in Zend_File_Transfer_Adapter_Abstract.php


if (isset($this->_options['ignoreNoFile'])) {
                    continue;
                }

This basic check to see if ignoreNoFile exists is not enough to tell the validation to skip errors because ignoreNoFIle is being set by default, but it's value is set to a boolean of false when you set an element to be required. In addition to checking if the options index exists, it should also check the boolean value of the option and only continue if it's true.

Yes, you are true. thank you for mentioning this.

Fixed with r12027

Changing issues in preparation for the 1.7.0 release.