From e3af1df3547d8b47ab8f8f002d238c25498212cc Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 2 Nov 2010 20:39:20 +0000 Subject: [PATCH] Fix misinterpration of HTML5 specification for email validation. Follow up: r75670 (JS), r75682 (PHP) --- includes/User.php | 4 ++-- .../phpunit/includes/UserIsValidEmailAddrTest.php | 11 ++++++----- .../mediawiki.specials.preferences.js | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/includes/User.php b/includes/User.php index 6d44b8de92..ab6f1c586e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 diff --git a/maintenance/tests/phpunit/includes/UserIsValidEmailAddrTest.php b/maintenance/tests/phpunit/includes/UserIsValidEmailAddrTest.php index 391857ed37..c1f34193ed 100644 --- a/maintenance/tests/phpunit/includes/UserIsValidEmailAddrTest.php +++ b/maintenance/tests/phpunit/includes/UserIsValidEmailAddrTest.php @@ -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" ); diff --git a/resources/mediawiki.specials/mediawiki.specials.preferences.js b/resources/mediawiki.specials/mediawiki.specials.preferences.js index e536bd3d7a..4663a42101 100644 --- a/resources/mediawiki.specials/mediawiki.specials.preferences.js +++ b/resources/mediawiki.specials/mediawiki.specials.preferences.js @@ -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 '$', -- 2.20.1