Make WordPress Core

Changeset 31158


Ignore:
Timestamp:
01/12/2015 04:20:47 AM (12 years ago)
Author:
jeremyfelt
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r31157 r31158  
    299299        foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
    300300                if ( 'path' === $field ) {
    301                         $details[ $field ] = array_filter( explode( '/', $details[ $field ] ) );
    302                         $details[ $field ] = trailingslashit( '/' . implode( '/', $details[ $field ] ) );
     301                        $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
    303302                }
    304303
  • trunk/tests/phpunit/tests/multisite/site.php

    r31157 r31158  
    592592        }
    593593
     594        /**
     595         * `update_blog_details()` does not resolve multiple slashes in the
     596         * middle of a path string.
     597         */
    594598        function test_update_blog_details_multiple_paths_middle_slashes() {
    595599                update_blog_details( 1, array( 'path' => 'multiple///dirs' ) );
    596600                $blog = get_blog_details( 1 );
    597                 $this->assertEquals( '/multiple/dirs/', $blog->path );
     601                $this->assertEquals( '/multiple///dirs/', $blog->path );
    598602        }
    599603
Note: See TracChangeset for help on using the changeset viewer.