Use a less complex approach for enforcing path slashes in `update_blog_details()`
Ensure leading and traling slashes are in place and don't touch anything in the middle. Validating with `array_filter()` would have missed a possible valid falsy path - `/my-path/0/`. Props nacin. Fixes #18117. git-svn-id: https://develop.svn.wordpress.org/trunk@31158 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d759c0ef23
commit
0eb9f7e414
|
@ -298,8 +298,7 @@ function update_blog_details( $blog_id, $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 ) {
|
||||
if ( 'path' === $field ) {
|
||||
$details[ $field ] = array_filter( explode( '/', $details[ $field ] ) );
|
||||
$details[ $field ] = trailingslashit( '/' . implode( '/', $details[ $field ] ) );
|
||||
$details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
|
||||
}
|
||||
|
||||
$update_details[ $field ] = $details[ $field ];
|
||||
|
|
|
@ -591,10 +591,14 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
|||
$this->assertEquals( '/multiple/dirs/', $blog->path );
|
||||
}
|
||||
|
||||
/**
|
||||
* `update_blog_details()` does not resolve multiple slashes in the
|
||||
* middle of a path string.
|
||||
*/
|
||||
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 );
|
||||
$this->assertEquals( '/multiple///dirs/', $blog->path );
|
||||
}
|
||||
|
||||
function test_update_blog_details_multiple_paths_leading_slash() {
|
||||
|
|
Loading…
Reference in New Issue