Make WordPress Core

Changeset 34104


Ignore:
Timestamp:
09/14/2015 01:58:03 AM (9 years ago)
Author:
dd32
Message:

When running on windows systems, normalise the capitalisation of the drive letter for more reliable string comparisons.

Props tyxla
Fixes #33265

Location:
trunk
Files:
2 edited

Legend:

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

    r34059 r34104  
    15761576 * Normalize a filesystem path.
    15771577 *
    1578  * Replaces backslashes with forward slashes for Windows systems, and ensures
    1579  * no duplicate slashes exist.
     1578 * On windows systems, replaces backslashes with forward slashes
     1579 * and forces upper-case drive letters.
     1580 * Ensures that no duplicate slashes exist.
    15801581 *
    15811582 * @since 3.9.0
     1583 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
    15821584 *
    15831585 * @param string $path Path to normalize.
     
    15871589    $path = str_replace( '\\', '/', $path );
    15881590    $path = preg_replace( '|/+|','/', $path );
     1591    if ( ':' === substr( $path, 1, 1 ) ) {
     1592        $path = ucfirst( $path );
     1593    }
    15891594    return $path;
    15901595}
  • trunk/tests/phpunit/tests/functions.php

    r32631 r34104  
    112112        foreach ($relative_paths as $path)
    113113            $this->assertFalse( path_is_absolute($path), "path_is_absolute('$path') should return false" );
     114    }
     115
     116    /**
     117     * @ticket 33265
     118     */
     119    function test_wp_normalize_path() {
     120        $paths = array(
     121            '/WINDOWS' => '/WINDOWS',
     122            'C:/' => 'C:/',
     123            'C:/WINDOWS' => 'C:/WINDOWS',
     124            'C:/WINDOWS/system32' => 'C:/WINDOWS/system32',
     125            '\\WINDOWS' => '/WINDOWS',
     126            'C:\\' => 'C:/',
     127            'C:\\WINDOWS' => 'C:/WINDOWS',
     128            'C:\\\\WINDOWS' => 'C:/WINDOWS',
     129            'C:\\WINDOWS\\system32' => 'C:/WINDOWS/system32',
     130            '\\\\sambashare\\foo' => '/sambashare/foo',
     131            'c:/windows' => 'C:/windows',
     132            'c:\\windows' => 'C:/windows',
     133        );
     134
     135        foreach ($paths as $original => $expected) {
     136            $this->assertEquals( $expected, wp_normalize_path( $original ) );
     137        }
    114138    }
    115139
Note: See TracChangeset for help on using the changeset viewer.