From 4902da091c98c1070f07840098e51dfdbd39304a Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 20 Mar 2018 19:06:09 +0000 Subject: [PATCH] Multisite: Use case-insensitive check on email domain whitelist. Props greatislander. Fixes #43148. git-svn-id: https://develop.svn.wordpress.org/trunk@42858 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 5 +++-- tests/phpunit/tests/multisite/wpmuValidateUserSignup.php | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 93662fa923..cc797a7bd0 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -497,8 +497,9 @@ function wpmu_validate_user_signup( $user_name, $user_email ) { $limited_email_domains = get_site_option( 'limited_email_domains' ); if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) { - $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); - if ( ! in_array( $emaildomain, $limited_email_domains ) ) { + $limited_email_domains = array_map( 'strtolower', $limited_email_domains ); + $emaildomain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) ); + if ( ! in_array( $emaildomain, $limited_email_domains, true ) ) { $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!' ) ); } } diff --git a/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php b/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php index 6b0bae584e..d9d3e71e2b 100644 --- a/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php +++ b/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php @@ -62,6 +62,14 @@ if ( is_multisite() ) : $this->assertContains( 'user_email', $v['errors']->get_error_codes() ); } + public function test_should_not_fail_for_emails_from_whitelisted_domains_with_mixed_case() { + $domains = array( 'foo.com', 'bar.org' ); + update_site_option( 'limited_email_domains', $domains ); + + $v = wpmu_validate_user_signup( 'foo123', 'foo@BAR.org' ); + $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() ); + } + public function test_should_fail_for_existing_user_name() { $u = self::factory()->user->create( array( 'user_login' => 'foo123' ) ); $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );