Make WordPress Core

Ticket #17433: 17433-4.diff

File 17433-4.diff, 2.9 KB (added by salcode, 10 years ago)

Updated to remove redundant check for single domain

  • src/wp-includes/formatting.php

     
    21692169        // Split the domain into subs
    21702170        $subs = explode( '.', $domain );
    21712171
    2172         // Assume the domain will have at least two subs
    2173         if ( 2 > count( $subs ) ) {
     2172        // Assume the domain will have at least two subs, whitelist localhost
     2173        if ( 2 > count( $subs ) && 'localhost' !== strtolower( $domain ) ) {
    21742174                /** This filter is documented in wp-includes/formatting.php */
    21752175                return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
    21762176        }
     
    24212421        // Split the domain into subs
    24222422        $subs = explode( '.', $domain );
    24232423
    2424         // Assume the domain will have at least two subs
    2425         if ( 2 > count( $subs ) ) {
    2426                 /** This filter is documented in wp-includes/formatting.php */
    2427                 return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
    2428         }
    2429 
    24302424        // Create an array that will contain valid subs
    24312425        $new_subs = array();
    24322426
     
    24442438                }
    24452439        }
    24462440
    2447         // If there aren't 2 or more valid subs
    2448         if ( 2 > count( $new_subs ) ) {
     2441        // If there aren't 2 or more valid subs, whitelist localhost
     2442        if ( 2 > count( $new_subs ) && 'localhost' !== strtolower( $domain ) ) {
    24492443                /** This filter is documented in wp-includes/formatting.php */
    24502444                return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
    24512445        }
  • tests/phpunit/tests/formatting/IsEmail.php

     
    99                        "bob@example.com",
    1010                        "phil@example.info",
    1111                        "ace@204.32.222.14",
    12                         "kevin@many.subdomains.make.a.happy.man.edu"
     12                        "kevin@many.subdomains.make.a.happy.man.edu",
     13                        "sal@localhost",
    1314                        );
    1415                foreach ( $data as $datum ) {
    1516                        $this->assertEquals( $datum, is_email( $datum ), $datum );
  • tests/phpunit/tests/formatting/SanitizeEmail.php

     
     1<?php
     2
     3/**
     4 * @group formatting
     5 */
     6class Tests_Formatting_SanitizeEmail extends WP_UnitTestCase {
     7        function test_returns_the_unmodified_email_address_if_it_is_valid() {
     8                $data = array(
     9                        "bob@example.com",
     10                        "phil@example.info",
     11                        "ace@204.32.222.14",
     12                        "kevin@many.subdomains.make.a.happy.man.edu",
     13                        "sal@localhost",
     14                        );
     15                foreach ( $data as $datum ) {
     16                        $this->assertEquals( $datum, sanitize_email( $datum ), $datum );
     17                }
     18        }
     19}