浏览代码

Added check for array fields to be integers in reverseTransform method. This prevents checkdate from getting strings as arguments and throwing incorrect ErrorException when submitting form with malformed (string) data in, for example, Date field. #2609

ondrowan 13 年之前
父节点
当前提交
8351a11286

+ 4 - 0
src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

@@ -142,6 +142,10 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
             ));
             ));
         }
         }
 
 
+        if (preg_match( '/^\d*$/', $value['month'] . $value['day'] . $value['year']) === 0) {
+            throw new TransformationFailedException('This is an invalid date');
+        }
+
         if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) {
         if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) {
             throw new TransformationFailedException('This is an invalid date');
             throw new TransformationFailedException('This is an invalid date');
         }
         }