From 9555882e902b849686e8e71254cd1a091abf0631 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 14 Sep 2015 01:58:03 +0000 Subject: [PATCH] When running on windows systems, normalise the capitalisation of the drive letter for more reliable string comparisons. Props tyxla Fixes #33265 git-svn-id: https://develop.svn.wordpress.org/trunk@34104 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 9 +++++++-- tests/phpunit/tests/functions.php | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index d726c07313..e0e98be7a5 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -1575,10 +1575,12 @@ function path_join( $base, $path ) { /** * Normalize a filesystem path. * - * Replaces backslashes with forward slashes for Windows systems, and ensures - * no duplicate slashes exist. + * On windows systems, replaces backslashes with forward slashes + * and forces upper-case drive letters. + * Ensures that no duplicate slashes exist. * * @since 3.9.0 + * @since 4.4.0 Ensures upper-case drive letters on Windows systems. * * @param string $path Path to normalize. * @return string Normalized path. @@ -1586,6 +1588,9 @@ function path_join( $base, $path ) { function wp_normalize_path( $path ) { $path = str_replace( '\\', '/', $path ); $path = preg_replace( '|/+|','/', $path ); + if ( ':' === substr( $path, 1, 1 ) ) { + $path = ucfirst( $path ); + } return $path; } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 528e8f1e82..69d9390edd 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -113,6 +113,30 @@ class Tests_Functions extends WP_UnitTestCase { $this->assertFalse( path_is_absolute($path), "path_is_absolute('$path') should return false" ); } + /** + * @ticket 33265 + */ + function test_wp_normalize_path() { + $paths = array( + '/WINDOWS' => '/WINDOWS', + 'C:/' => 'C:/', + 'C:/WINDOWS' => 'C:/WINDOWS', + 'C:/WINDOWS/system32' => 'C:/WINDOWS/system32', + '\\WINDOWS' => '/WINDOWS', + 'C:\\' => 'C:/', + 'C:\\WINDOWS' => 'C:/WINDOWS', + 'C:\\\\WINDOWS' => 'C:/WINDOWS', + 'C:\\WINDOWS\\system32' => 'C:/WINDOWS/system32', + '\\\\sambashare\\foo' => '/sambashare/foo', + 'c:/windows' => 'C:/windows', + 'c:\\windows' => 'C:/windows', + ); + + foreach ($paths as $original => $expected) { + $this->assertEquals( $expected, wp_normalize_path( $original ) ); + } + } + function test_wp_unique_filename() { $testdir = DIR_TESTDATA . '/images/';