diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index e1c70e1a8d..72ebbaa3a8 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -296,8 +296,14 @@ function update_blog_details( $blog_id, $details = array() ) { $update_details = array(); $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); - foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) - $update_details[$field] = $details[$field]; + foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { + if ( 'path' === $field ) { + $details[ $field ] = array_filter( explode( '/', $details[ $field ] ) ); + $details[ $field ] = trailingslashit( '/' . implode( '/', $details[ $field ] ) ); + } + + $update_details[ $field ] = $details[ $field ]; + } $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index e894a9aadc..73cbd2872b 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -343,7 +343,7 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $blog = get_blog_details( $blog_id ); $this->assertEquals( 'example.com', $blog->domain ); - $this->assertEquals( 'my_path/', $blog->path ); + $this->assertEquals( '/my_path/', $blog->path ); $this->assertEquals( '0', $blog->spam ); } @@ -542,6 +542,79 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $test_action_counter++; } + /** + * When the path for a site is updated with update_blog_details(), the final + * path should have a leading and trailing slash. When multiple directories + * are part of the path, only one slash should separate each directory. + * + * @ticket 18117 + */ + function test_update_blog_details_single_path_no_slashes() { + update_blog_details( 1, array( 'path' => 'my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_double_trailing_slashes() { + update_blog_details( 1, array( 'path' => 'my_path//' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_double_leading_slashes() { + update_blog_details( 1, array( 'path' => '//my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_single_trailing_slash() { + update_blog_details( 1, array( 'path' => 'my_path/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_single_leading_slashes() { + update_blog_details( 1, array( 'path' => '/my_path' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_single_path_both_slashes() { + update_blog_details( 1, array( 'path' => '/my_path/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/my_path/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_no_slashes() { + update_blog_details( 1, array( 'path' => 'multiple/dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_middle_slashes() { + update_blog_details( 1, array( 'path' => 'multiple///dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_leading_slash() { + update_blog_details( 1, array( 'path' => '/multiple/dirs' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_trailing_slash() { + update_blog_details( 1, array( 'path' => 'multiple/dirs/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + + function test_update_blog_details_multiple_paths_both_slashes() { + update_blog_details( 1, array( 'path' => '/multiple/dirs/' ) ); + $blog = get_blog_details( 1 ); + $this->assertEquals( '/multiple/dirs/', $blog->path ); + } + /** * Test cached data for a site that does not exist and then again after it exists. *