Ticket #35274: 35274.2.diff
File 35274.2.diff, 3.2 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/network.php
27 27 } 28 28 29 29 /** 30 * Allow subdomain install 30 * Allow subdomain install. 31 31 * 32 32 * @since 3.0.0 33 * @return bool Whether subdomain install is allowed 33 * 34 * @return bool Whether a subdomain install is allowed. 34 35 */ 35 36 function 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 ) ) { 38 42 return false; 39 43 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 40 53 return true; 41 54 } 42 55 … … 159 172 $subdomain_install = true; 160 173 } else { 161 174 $subdomain_install = false; 162 if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions 175 if ( $got_mod_rewrite = got_mod_rewrite() ) { // dangerous assumptions 163 176 echo '<div class="updated inline"><p><strong>' . __( 'Note:' ) . '</strong> '; 164 177 /* translators: %s: mod_rewrite */ 165 178 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. 4 require_once ABSPATH . '/wp-admin/includes/network.php'; 5 6 /** 7 * @group multisite 8 */ 9 class 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 }