Browse Source

[ZF-11819] Zend_Filter_Input
Fixed case where PHP Notice emitted when validator metacommand value is empty array


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24504 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 years ago
parent
commit
5ec4d6c0fb
2 changed files with 26 additions and 5 deletions
  1. 7 5
      library/Zend/Filter/Input.php
  2. 19 0
      tests/Zend/Filter/InputTest.php

+ 7 - 5
library/Zend/Filter/Input.php

@@ -851,11 +851,13 @@ class Zend_Filter_Input
                     if (is_array($rule)) {
                     if (is_array($rule)) {
                         $keys      = array_keys($rule);
                         $keys      = array_keys($rule);
                         $classKey  = array_shift($keys);
                         $classKey  = array_shift($keys);
-                        $ruleClass = $rule[$classKey];
-                        if ($ruleClass === 'NotEmpty') {
-                            $foundNotEmptyValidator = true;
-                            // field may not be empty, we are ready
-                            break 1;
+                        if (isset($rule[$classKey])) {
+                            $ruleClass = $rule[$classKey];
+                            if ($ruleClass === 'NotEmpty') {
+                                $foundNotEmptyValidator = true;
+                                // field may not be empty, we are ready
+                                break 1;
+                            }
                         }
                         }
                     }
                     }
 
 

+ 19 - 0
tests/Zend/Filter/InputTest.php

@@ -2282,6 +2282,25 @@ class Zend_Filter_InputTest extends PHPUnit_Framework_TestCase
         $input = new Zend_Filter_Input( null, $validators, $data, $options );
         $input = new Zend_Filter_Input( null, $validators, $data, $options );
         $this->assertFalse($input->isValid(), 'If the NotEmpty validator is an array, the NotEmpty validator is ignored !');
         $this->assertFalse($input->isValid(), 'If the NotEmpty validator is an array, the NotEmpty validator is ignored !');
     }
     }
+    
+    /**
+     * This test doesn't include any assertions as it's purpose is to 
+     * ensure that passing an empty array value into a $validators rule 
+     * doesn't cause a notice to be emitted
+     *  
+     * @group ZF-11819
+     */
+    public function testValidatorRuleCanHaveEmptyArrayAsMetacommandValue()
+    {
+        $filters = array('html' => 'StringTrim',);
+        $validators = array(
+            'html' => array('NotEmpty', 'presence' => 'required'),
+            'perms' => array('Int', 'default' => array()),
+        );
+
+        $validate = new Zend_Filter_Input($filters, $validators);
+        $validate->isValid();
+    }    
 }
 }
 
 
 class MyZend_Filter_Date implements Zend_Filter_Interface
 class MyZend_Filter_Date implements Zend_Filter_Interface