Enforce leading and trailing slashes on paths updated with update_blog_details()

In multisite, core expects the stored value for a site's path to have leading and trailing slashes. When these slashes are missing, it becomes impossible to visit the site.

This enforces proper `/path/` creation in `update_blog_details()`, most likely used when updating an existing site through `site-info.php`.

Props earnjam, simonwheatley.

Fixes #18117. Fixes #23865.


git-svn-id: https://develop.svn.wordpress.org/trunk@31155 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2015-01-12 01:42:46 +00:00
parent 0b993ffe35
commit f9e9287875
2 changed files with 82 additions and 3 deletions
+74 -1
View File
@@ -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.
*