[+BUGFIX] Extbase (Validation): E-mail address with space at the end is invalid
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Mon, 13 Jun 2011 20:35:38 +0000 (22:35 +0200)
committerBastian Waidelich <bastian@typo3.org>
Tue, 14 Jun 2011 18:14:36 +0000 (20:14 +0200)
Add regex-check for additional whitespaces at the end.

Thanks to Marc Bastian Heinrichs

Change-Id: I784c25d50cc3114e93a7d015d7dd5d538fb2315e
Resolves: #27305

typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php

index 027ce20..59c9d34 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -37,7 +37,7 @@ 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
         *
@@ -47,16 +47,17 @@ class Tx_Extbase_Validation_Validator_EmailAddressValidator extends Tx_Extbase_V
        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-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-5][0-5])\.){3}(?:(?:\d{1,2}|1\d{1,2}|2[0-5][0-5]))
+                                               (?:(?:\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]))
                                        )
-                                       \b
-                               /ix', $value)) return TRUE;
+                               $/Dix', $value)) {
+                       return TRUE;
+               }
                $this->addError('The given subject was not a valid email address.', 1221559976);
                return FALSE;
        }
index 6713dc3..57f4eb2 100644 (file)
@@ -72,7 +72,8 @@ class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest exten
                        array('@typo3.org'),
                        array('someone@typo3.'),
                        array('local@192.168.2'),
-                       array('local@192.168.270.1')
+                       array('local@192.168.270.1'),
+                       array('just@test.invalid ')
                );
        }