[+BUGFIX] Extbase (Validation): EmailAddressValidator detects 'andreas@foerthner...
authorJochen Rau <j.rau@web.de>
Tue, 19 Jan 2010 00:06:05 +0000 (00:06 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 19 Jan 2010 00:06:05 +0000 (00:06 +0000)
typo3/sysext/extbase/Classes/Validation/Validator/EmailAddressValidator.php
typo3/sysext/extbase/Tests/Validation/Validator/EmailAddressValidator_testcase.php

index 74ac938..027ce20 100644 (file)
@@ -48,7 +48,7 @@ class Tx_Extbase_Validation_Validator_EmailAddressValidator extends Tx_Extbase_V
                $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)|
index 679ceac..cee8547 100755 (executable)
 class Tx_Extbase_Validation_Validator_EmailAddressValidator_testcase extends Tx_Extbase_BaseTestCase {
 
        /**
-        * An array of valid email addresses
-        * @var array
+        * Data provider with valid email addresses
+        *
+        * @return array
         */
-       protected $validAddresses;
-       
-       public function setUp() {
-               $this->validAddresses = array(
-                               'andreas.foerthner@netlogix.de',
-                               'user@localhost',
-                               'user@localhost.localdomain',
-                               'info@guggenheim.museum',
-                               'just@test.invalid',
-                               'just+spam@test.de',
-                               'local@192.168.0.2)'
-                       );
+       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')
+               );
        }
-       
+
        /**
         * @test
         * @dataProvider validAddresses
         */
-       public function emailAddressValidatorReturnsTrueForAValidEmailAddress() {
+       public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
                $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
                foreach ($this->validAddresses as $address) {
                        $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
@@ -71,6 +70,7 @@ class Tx_Extbase_Validation_Validator_EmailAddressValidator_testcase extends Tx_
        public function invalidAddresses() {
                return array(
                        array('andreas.foerthner@'),
+                       array('andreas@foerthner@example.com'),
                        array('@typo3.org'),
                        array('someone@typo3.'),
                        array('local@192.168.2'),
@@ -82,7 +82,7 @@ class Tx_Extbase_Validation_Validator_EmailAddressValidator_testcase extends Tx_
         * @test
         * @dataProvider invalidAddresses
         */
-       public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress() {
+       public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
                $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
                $this->assertFalse($emailAddressValidator->isValid($address));
        }