ZF-11710: Zend_Filter_Input considers empty Arrays as valid data
Description
When an empty array is given to a Zend_Filter_Input for validation, it's considered as not empty and isValid() method returns true.
Here is a simple snippet that reproduce the bug :
<?php
require_once 'Zend/Filter/Input.php';
require_once 'Zend/Validate/NotEmpty.php';
$input = new Zend_Filter_Input(null, array('test' => array()));
$input->setData(array('test' => array()));
if ($input->isValid()) {
echo "Array is not empty\n";
} else {
echo "Array is empty\n";
}
$input->setData(array('test' => ''));
if ($input->isValid()) {
echo "String is not empty\n";
} else {
echo "String is empty\n";
}
It will display : Array is not empty String is empty
As Zend_Validate_NotEmpty, Zend_Filter_Input should considers that an empty array is an empty value, and is not valid.
Comments
Posted by Lucas Corbeaux (lucas.corbeaux@gmail.com) on 2011-08-30T19:36:49.000+0000
I made a little patch that seems to solve the problem and that don't break unit tests, but it seems that I can't add an attachment. If anyone tell me how, I'll put it here :)
Posted by Matthew Weier O'Phinney (matthew) on 2011-08-30T20:16:20.000+0000
You need to have signed a CLA in order to attach files. The reason is that we cannot apply patches coming from non-CLA'd sources. Once you have, you should see the "Attach Files" entry under the "More Actions" dropdown at the top of the issue.
Posted by Lucas Corbeaux (lucas.corbeaux@gmail.com) on 2011-08-30T20:50:13.000+0000
Thank you for your answer, I thought CLA was only needed for commiting, not for attaching files. I'm taking care of it quickly.
Posted by Lucas Corbeaux (lucas.corbeaux@gmail.com) on 2011-09-01T19:06:33.000+0000
Here is a patch that works for me applied on the 1.11.10 tag.
With this little "fix", empty arrays given to Zend_Filter_Input are no longer considered as valid.