Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9.7
-
Fix Version/s: 1.10.0
-
Component/s: Zend_File_Transfer
-
Labels:None
Description
Bug in Zend/File/Transfer/Adapter/Abstract.php
method addValidators;
$validators = array(
array('MimeType', true, array('image/jpeg', 'image/gif', 'image/png')),
array('FilesSize', true, array('max' => '1MB', 'messages' => 'файл больше 1MБ')),
);
$this->_upload->addValidators($validators, 'img');
set validators for all files, because error in block
switch (true) {
case (0 == $argc):
break;
case (1 <= $argc):
$validator = array_shift($validatorInfo);
case (2 <= $argc):
$breakChainOnFailure = array_shift($validatorInfo);
case (3 <= $argc):
$options = array_shift($validatorInfo);
case (4 <= $argc):
$files = array_shift($validatorInfo);
default:
$this->addValidator($validator, $breakChainOnFailure, $options, $files);
break;
Must be changed to:
if ($argc > 0) { $validator = array_shift($validatorInfo); if (2 <= $argc) $breakChainOnFailure = array_shift($validatorInfo); if (3 <= $argc) $options = array_shift($validatorInfo); if (4 <= $argc) $files = array_shift($validatorInfo); $this->addValidator($validator, $breakChainOnFailure, $options, $files); }
Invalid use switch
See on oficial site php.net
<?php
switch ($i) {
case 0:
echo "i equals 0";
case 1:
echo "i equals 1";
case 2:
echo "i equals 2";
}
?>
Here, if $i is equal to 0, PHP would execute all of the echo statements! If $i is equal to 1, PHP would execute the last two echo statements. You would get the expected behavior ('i equals 2' would be displayed) only if $i is equal to 2. Thus, it is important not to forget break statements (even though you may want to avoid supplying them on purpose under certain circumstances).
Code is not correct. Test again, because this code always run case 3 and 4 - set files to null always.
$validators = array(
array('MimeType', true, array('image/jpeg', 'image/gif', 'image/png')),
array('FilesSize', true, array('max' => '1MB', 'messages' => 'файл больше 1MБ')),
);
$this->_upload->addValidators($validators, 'img');
Test this!!! Case 1 - true always, and not has break - run cases 2-4. This is error!!!