Fix misinterpration of HTML5 specification for email validation.
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 2 Nov 2010 20:39:20 +0000 (20:39 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 2 Nov 2010 20:39:20 +0000 (20:39 +0000)
Follow up: r75670 (JS), r75682 (PHP)

includes/User.php
maintenance/tests/phpunit/includes/UserIsValidEmailAddrTest.php
resources/mediawiki.specials/mediawiki.specials.preferences.js

index 6d44b8d..ab6f1c5 100644 (file)
@@ -655,8 +655,8 @@ class User {
                ^                      # start of string
                [$rfc5322_atext\\.]+    # user part which is liberal :p
                @                      # 'apostrophe'
-               [$rfc1034_ldh_str]     # Domain first character
-               [$rfc1034_ldh_str\\.]+  # Second char and following can include dot
+               [$rfc1034_ldh_str]+       # First domain part
+               (\\.[$rfc1034_ldh_str]+)+  # Following part prefixed with a dot
                $                      # End of string
                /ix" ; // case Insensitive, eXtended 
 
index 391857e..c1f3419 100644 (file)
@@ -27,7 +27,8 @@ class UserIsValidEmailAddrTest extends PHPUnit_Framework_TestCase {
                $this->valid( 'USER@eXAMPLE.com' );
        }
        function testEmailWithAPlusInUserName() {
-               $this->valid( 'user+sub@localdomain' );
+               $this->valid( 'user+sub@example.com' );
+               $this->valid( 'user+@example.com' );
        }
        function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() {
                $this->invalid( " user@host" );
@@ -43,10 +44,10 @@ class UserIsValidEmailAddrTest extends PHPUnit_Framework_TestCase {
        function testEmailDomainCanNotBeginWithDot() {
                $this->invalid( "user@." );
                $this->invalid( "user@.localdomain" );
-               $this->valid( "user@localdomain." );
-               $this->valid( "user.@localdomain" );
-               $this->valid( ".@localdomain" );
-               $this->valid( ".@a............" );
+               $this->invalid( "user@localdomain." );
+               $this->invalid( "user.@localdomain" );
+               $this->invalid( ".@localdomain" );
+               $this->invalid( ".@a............" );
        }
        function testEmailWithFunnyCharacters() {
                $this->valid( "\$user!ex{this}@123.com" );
index e536bd3..4663a42 100644 (file)
@@ -112,11 +112,11 @@ wfValidateEmail = function( mailtxt ) {
                // "apostrophe"
                '@'
                +
-               // Domain first character
-               '[' + rfc1034_ldh_str + ']'
+               // Domain first part 
+               '[' + rfc1034_ldh_str + ']+'
                +
-               // second char and following can include dot
-               '[' + rfc1034_ldh_str + '\\.' + ']' + '+'
+               // Second part and following are separated by a dot
+               '(\\.[' + rfc1034_ldh_str + ']+)+'
                +
                // End of string
                '$',