Make WordPress Core

Ticket #35274: 35274.2.diff

File 35274.2.diff, 3.2 KB (added by stevegrunwell, 9 years ago)

Updated diff that restores the original regex for IP addresses rather than using filter_var()

  • src/wp-admin/includes/network.php

     
    2727}
    2828
    2929/**
    30  * Allow subdomain install
     30 * Allow subdomain install.
    3131 *
    3232 * @since 3.0.0
    33  * @return bool Whether subdomain install is allowed
     33 *
     34 * @return bool Whether a subdomain install is allowed.
    3435 */
    3536function allow_subdomain_install() {
    36         $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
    37         if ( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
     37        $home   = get_option( 'home' );
     38        $domain = preg_replace( '|^https?://([^/]+)|', '$1', $home );
     39
     40        // The site isn't at the root of the domain.
     41        if ( parse_url( $home, PHP_URL_PATH ) ) {
    3842                return false;
    3943
     44        // "localhost" is a reserved domain.
     45        } elseif ( 'localhost' === $domain ) {
     46                return false;
     47
     48        // IP addresses do not permit subdomains.
     49        } elseif ( preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) {
     50                return false;
     51        }
     52
    4053        return true;
    4154}
    4255
     
    159172                $subdomain_install = true;
    160173        } else {
    161174                $subdomain_install = false;
    162                 if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions 
     175                if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions
    163176                        echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> ';
    164177                        /* translators: %s: mod_rewrite */
    165178                        printf( __( 'Please make sure the Apache %s module is installed as it will be used at the end of this installation.' ),
  • tests/phpunit/tests/multisite/allowSubdomainInstall.php

     
     1<?php
     2
     3// This file is not normally loaded for unit tests.
     4require_once ABSPATH . '/wp-admin/includes/network.php';
     5
     6/**
     7 * @group multisite
     8 */
     9class Tests_Multisite_AllowSubdomainInstall extends WP_UnitTestCase {
     10
     11        public function test_allow_subdomain_install_with_regular_domain() {
     12                update_option( 'home', 'http://example.com' );
     13
     14                $this->assertTrue( allow_subdomain_install() );
     15        }
     16
     17        public function test_allow_subdomain_install_with_https_domain() {
     18                update_option( 'home', 'https://example.com' );
     19
     20                $this->assertTrue( allow_subdomain_install() );
     21        }
     22
     23        public function test_allow_subdomain_install_within_remote_path() {
     24                update_option( 'home', 'http://example.com/mysite' );
     25
     26                $this->assertFalse( allow_subdomain_install() );
     27        }
     28
     29        public function test_allow_subdomain_install_with_localhost() {
     30                update_option( 'home', 'http://localhost' );
     31
     32                $this->assertFalse( allow_subdomain_install() );
     33        }
     34
     35        public function test_allow_subdomain_install_with_ip_address() {
     36                update_option( 'home', 'http://192.168.1.1' );
     37
     38                $this->assertFalse( allow_subdomain_install() );
     39        }
     40}