[BUGFIX] Check if validationrules are set before foreach statement 43/38843/3
authorRuud <ruudsilvrants@gmail.com>
Tue, 21 Apr 2015 09:21:47 +0000 (11:21 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Tue, 21 Apr 2015 10:12:06 +0000 (12:12 +0200)
The ValidationUtility now checks if there are any rules set,
before trying to use the variable in the foreach loop.

Resolves: #66508
Releases: master, 6.2
Change-Id: I201986d88666d8de8a84de6581d2ea06da7374c2
Reviewed-on: http://review.typo3.org/38843
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/form/Classes/Utility/ValidatorUtility.php

index 37629ba..f560be7 100644 (file)
@@ -112,21 +112,23 @@ class ValidatorUtility implements \TYPO3\CMS\Core\SingletonInterface {
                $prefix = $this->getPrefix();
                $this->errors[$prefix] = array();
                $result = TRUE;
-               foreach ($this->rules[$prefix] as $key => $element) {
-                       $rule = $element['instance'];
-                       $fieldName = $element['fieldName'];
-                       if ($rule->isValid()) {
-                               continue;
-                       }
-                       $result = FALSE;
-                       if (!isset($this->errors[$prefix][$fieldName])) {
-                               $this->errors[$prefix][$fieldName] = array();
-                       }
-                       $error = $rule->getError();
-                       $this->errors[$prefix][$fieldName][$key][$key + 1] = $error['cObj'];
-                       $this->errors[$prefix][$fieldName][$key][($key + 1) . '.'] = $error['cObj.'];
-                       if ($element['breakOnError']) {
-                               break;
+               if (is_array($this->rules[$prefix])) {
+                       foreach ($this->rules[$prefix] as $key => $element) {
+                               $rule = $element['instance'];
+                               $fieldName = $element['fieldName'];
+                               if ($rule->isValid()) {
+                                       continue;
+                               }
+                               $result = FALSE;
+                               if (!isset($this->errors[$prefix][$fieldName])) {
+                                       $this->errors[$prefix][$fieldName] = array();
+                               }
+                               $error = $rule->getError();
+                               $this->errors[$prefix][$fieldName][$key][$key + 1] = $error['cObj'];
+                               $this->errors[$prefix][$fieldName][$key][($key + 1) . '.'] = $error['cObj.'];
+                               if ($element['breakOnError']) {
+                                       break;
+                               }
                        }
                }
                return $result;