[BUGFIX] EXT:form Validation of email 59/47059/6
authorFlorian Mast <flo.mast@web.de>
Fri, 4 Mar 2016 14:53:07 +0000 (15:53 +0100)
committerJan Helke <typo3@helke.de>
Fri, 4 Mar 2016 18:39:51 +0000 (19:39 +0100)
Validation of email should respect empty value

Resolves: #54534
Releases: master,7.6
Change-Id: I40c865b42fe7960dd7ab85f710df1045cd04adf0
Reviewed-on: https://review.typo3.org/47059
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/form/Classes/Domain/Validator/EmailValidator.php
typo3/sysext/form/Tests/Unit/Validator/EmailValidatorTest.php

index df8a266..edb05fc 100755 (executable)
@@ -14,6 +14,11 @@ namespace TYPO3\CMS\Form\Domain\Validator;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Class EmailValidator
+ */
 class EmailValidator extends AbstractValidator
 {
     /**
@@ -32,7 +37,11 @@ class EmailValidator extends AbstractValidator
      */
     public function isValid($value)
     {
-        if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($value)) {
+        if (empty($value) || !is_string($value)) {
+            return;
+        }
+
+        if (!GeneralUtility::validEmail($value)) {
             $this->addError(
                 $this->renderMessage(
                     $this->options['errorMessage'][0],
index cab00fe..f9ed70b 100644 (file)
@@ -31,7 +31,9 @@ class EmailValidatorTest extends AbstractValidatorTest
     {
         return array(
             'a@b.de' => array('a@b.de'),
-            'somebody@mymac.local' => array('somebody@mymac.local')
+            'somebody@mymac.local' => array('somebody@mymac.local'),
+            'empty value' => array(''),
+            'unexpected value' => array(array()),
         );
     }