Make WordPress Core

Changeset 36881


Ignore:
Timestamp:
03/08/2016 05:59:45 AM (9 years ago)
Author:
dd32
Message:

Filesystem: Support Windows shares/DFS roots in wp_normalize_path().

Props rilwis for initial patch.
Fixes #35996.

Location:
trunk
Files:
2 edited

Legend:

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

    r36644 r36881  
    16881688 * On windows systems, replaces backslashes with forward slashes
    16891689 * and forces upper-case drive letters.
    1690  * Ensures that no duplicate slashes exist.
     1690 * Allows for two leading slashes for Windows network shares, but
     1691 * ensures that all other duplicate slashes are reduced to a single.
    16911692 *
    16921693 * @since 3.9.0
    16931694 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
     1695 * @since 4.5.0 Allows for Windows network shares.
    16941696 *
    16951697 * @param string $path Path to normalize.
     
    16981700function wp_normalize_path( $path ) {
    16991701    $path = str_replace( '\\', '/', $path );
    1700     $path = preg_replace( '|/+|','/', $path );
     1702    $path = preg_replace( '|(?<=.)/+|', '/', $path );
    17011703    if ( ':' === substr( $path, 1, 1 ) ) {
    17021704        $path = ucfirst( $path );
  • trunk/tests/phpunit/tests/file.php

    r31937 r36881  
    176176    }
    177177
     178    /**
     179     * @dataProvider data_wp_normalize_path
     180     */
     181    function test_wp_normalize_path( $path, $expected ) {
     182        $this->assertEquals( $expected, wp_normalize_path( $path ) );
     183    }
     184    function data_wp_normalize_path() {
     185        return array(
     186            // Windows paths
     187            array( 'C:\\www\\path\\', 'C:/www/path/' ),
     188            array( 'C:\\www\\\\path\\', 'C:/www/path/' ),
     189            array( 'c:/www/path', 'C:/www/path' ),
     190            array( 'c:\\www\\path\\', 'C:/www/path/' ), // uppercase drive letter
     191            array( '\\\\Domain\\DFSRoots\\share\\path\\', '//Domain/DFSRoots/share/path/' ),
     192            array( '\\\\Server\\share\\path', '//Server/share/path' ),
     193
     194            // Linux paths
     195            array( '/www/path/', '/www/path/' ),
     196            array( '/www/path/////', '/www/path/' ),
     197            array( '/www/path', '/www/path' ),
     198        );
     199    }
    178200}
Note: See TracChangeset for help on using the changeset viewer.