WordPress.org

Make WordPress Core

Ticket #18117: 18117.4.diff

File 18117.4.diff, 4.3 KB (added by earnjam, 5 years ago)
  • src/wp-includes/ms-blogs.php

     
    296296
    297297        $update_details = array();
    298298        $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
    299         foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
    300                 $update_details[$field] = $details[$field];
     299        foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
     300                if ( 'path' === $field ) {
     301                        $details[ $field ] = array_filter( explode( '/', $details[ $field ] ) );
     302                        $details[ $field ] = trailingslashit( '/' . implode( '/', $details[ $field ] ) );
     303                }
    301304
     305                $update_details[ $field ] = $details[ $field ];
     306        }
     307
    302308        $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
    303309
    304310        if ( false === $result )
  • tests/phpunit/tests/multisite/site.php

     
    293293                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
    294294                $this->assertInternalType( 'int', $blog_id );
    295295
    296                 $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path/') );
     296                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '/my_path/') );
    297297                $this->assertTrue( $result );
    298298
    299299                $blog = get_blog_details( $blog_id );
    300300                $this->assertEquals( 'example.com', $blog->domain );
    301                 $this->assertEquals( 'my_path/', $blog->path );
     301                $this->assertEquals( '/my_path/', $blog->path );
    302302                $this->assertEquals( '0', $blog->spam );
    303303
    304304                $result = update_blog_details( $blog_id, array('domain' => 'example2.com','spam' => 1) );
    305305                $this->assertTrue( $result );
    306306                $blog = get_blog_details( $blog_id );
    307307                $this->assertEquals( 'example2.com', $blog->domain );
    308                 $this->assertEquals( 'my_path/', $blog->path );
     308                $this->assertEquals( '/my_path/', $blog->path );
    309309                $this->assertEquals( '1', $blog->spam );
    310310
    311311                $result = update_blog_details( $blog_id );
    312312                $this->assertFalse( $result );
    313313                $blog = get_blog_details( $blog_id );
    314314                $this->assertEquals( 'example2.com', $blog->domain );
    315                 $this->assertEquals( 'my_path/', $blog->path );
     315                $this->assertEquals( '/my_path/', $blog->path );
    316316                $this->assertEquals( '1', $blog->spam );
    317317
    318318                $test_action_counter = 0;
     
    444444        }
    445445
    446446        /**
     447         * Check the path for a sub-directory site is correctly sanitised,
     448         * and has a trailing slash.
     449         *
     450         * @ticket 18117
     451         */
     452        function test_update_blog_sanitises_subdirectory_path() {
     453
     454                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     455                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) );
     456                $this->assertInternalType( 'int', $blog_id );
     457
     458                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path') );
     459                $blog = get_blog_details( $blog_id );
     460                $this->assertEquals( '/my_path/', $blog->path );
     461
     462                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path//') );
     463                $blog = get_blog_details( $blog_id );
     464                $this->assertEquals( '/my_path/', $blog->path );
     465
     466                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '//my_path') );
     467                $blog = get_blog_details( $blog_id );
     468                $this->assertEquals( '/my_path/', $blog->path );
     469
     470                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => '/my_path') );
     471                $blog = get_blog_details( $blog_id );
     472                $this->assertEquals( '/my_path/', $blog->path );
     473
     474                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'multiple/dirs') );
     475                $blog = get_blog_details( $blog_id );
     476                $this->assertEquals( '/multiple/dirs/', $blog->path );
     477
     478                $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'multiple///dirs') );
     479                $blog = get_blog_details( $blog_id );
     480                $this->assertEquals( '/multiple/dirs/', $blog->path );
     481        }
     482
     483        /**
    447484         * Test cached data for a site that does not exist and then again after it exists.
    448485         *
    449486         * @ticket 23405