Make WordPress Core

Ticket #43148: 43148.1.diff

File 43148.1.diff, 1.8 KB (added by greatislander, 7 years ago)

Add test, add true parameter to in_array()

  • src/wp-includes/ms-functions.php

    diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php
    index c878739d6e..1396bc4bff 100644
    a b function wpmu_validate_user_signup( $user_name, $user_email ) { 
    497497
    498498        $limited_email_domains = get_site_option( 'limited_email_domains' );
    499499        if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) {
    500                 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
    501                 if ( ! in_array( $emaildomain, $limited_email_domains ) ) {
     500                $allowed_domains = array_map( 'strtolower', $limited_email_domains );
     501                $emaildomain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) );
     502                if ( ! in_array( $emaildomain, $allowed_domains, true ) ) {
    502503                        $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!' ) );
    503504                }
    504505        }
  • tests/phpunit/tests/multisite/wpmuValidateUserSignup.php

    diff --git a/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php b/tests/phpunit/tests/multisite/wpmuValidateUserSignup.php
    index 6b0bae584e..d9d3e71e2b 100644
    a b if ( is_multisite() ) : 
    6262                        $this->assertContains( 'user_email', $v['errors']->get_error_codes() );
    6363                }
    6464
     65                public function test_should_not_fail_for_emails_from_whitelisted_domains_with_mixed_case() {
     66                        $domains = array( 'foo.com', 'bar.org' );
     67                        update_site_option( 'limited_email_domains', $domains );
     68
     69                        $v = wpmu_validate_user_signup( 'foo123', 'foo@BAR.org' );
     70                        $this->assertNotContains( 'user_email', $v['errors']->get_error_codes() );
     71                }
     72
    6573                public function test_should_fail_for_existing_user_name() {
    6674                        $u = self::factory()->user->create( array( 'user_login' => 'foo123' ) );
    6775                        $v = wpmu_validate_user_signup( 'foo123', 'foo@example.com' );