[BUGFIX] email validator
authorMarkus Günther <mail@markus-guenther.de>
Thu, 9 Aug 2012 16:33:40 +0000 (18:33 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 13 Aug 2012 13:42:48 +0000 (15:42 +0200)
The actuall email validator uses a regex to validate email addresses.
The TYPO3 core offers a method in t3lib_div to validate email addresses.
This patch replace the regex with t3lib_div::validEmail()

Change-Id: I8157a61b8f056d0a60510ec3a7ba9dcb182cb0e5
Releases: 6.0, 4.7
Resolves: #6970
FLOW3 issue: #39714
Reviewed-on: http://review.typo3.org/13550
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Ingo Pfennigstorf
Tested-by: Ingo Pfennigstorf
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/BeforeExtbase14/EmailAddressValidatorTest.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php

index 6b44b08..0953f22 100644 (file)
@@ -38,26 +38,16 @@ class Tx_Extbase_Validation_Validator_EmailAddressValidator extends Tx_Extbase_V
         * Checks if the given value is a valid email address.
         * If at least one error occurred, the result is FALSE.
         *
-        * The regexp is a modified version of the last one shown on
-        * http://www.regular-expressions.info/email.html
-        *
         * @param mixed $value The value that should be validated
         * @return boolean TRUE if the value is valid, FALSE if an error occured
         */
        public function isValid($value) {
                $this->errors = array();
-               if (is_string($value) && preg_match('
-                               /^
-                                       [a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*
-                                       @
-                                       (?:
-                                               (?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z]{2}|aero|asia|biz|cat|com|edu|coop|gov|info|int|invalid|jobs|localdomain|mil|mobi|museum|name|net|org|pro|tel|travel)|
-                                               localhost|
-                                               (?:(?:\d{1,2}|1\d{1,2}|2[0-4][0-9]|25[0-5])\.){3}(?:(?:\d{1,2}|1\d{1,2}|2[0-4][0-9]|25[0-5]))
-                                       )
-                               $/Dix', $value)) {
+
+               if (is_string($value) && t3lib_div::validEmail($value)) {
                        return TRUE;
                }
+
                $this->addError('The given subject was not a valid email address.', 1221559976);
                return FALSE;
        }
index adc6636..53f1dd2 100644 (file)
@@ -45,12 +45,10 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_EmailAddressVal
        public function validAddresses() {
                return array(
                        array('andreas.foerthner@netlogix.de'),
-                       array('user@localhost'),
                        array('user@localhost.localdomain'),
                        array('info@guggenheim.museum'),
                        array('just@test.invalid'),
-                       array('just+spam@test.de'),
-                       array('local@192.168.0.2')
+                       array('just+spam@test.de')
                );
        }
 
index 7b25cec..c552ef6 100644 (file)
@@ -40,13 +40,10 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest exten
        public function validAddresses() {
                return array(
                        array('andreas.foerthner@netlogix.de'),
-                       array('user@localhost'),
                        array('user@localhost.localdomain'),
                        array('info@guggenheim.museum'),
                        array('just@test.invalid'),
-                       array('just+spam@test.de'),
-                       array('just+spam@192.168.249.100'),
-                       array('local@192.168.0.2')
+                       array('just+spam@test.de')
                );
        }