diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index bcd56f748d..7d4a51f939 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -1687,17 +1687,19 @@ function path_join( $base, $path ) { * * On windows systems, replaces backslashes with forward slashes * and forces upper-case drive letters. - * Ensures that no duplicate slashes exist. + * Allows for two leading slashes for Windows network shares, but + * ensures that all other duplicate slashes are reduced to a single. * * @since 3.9.0 * @since 4.4.0 Ensures upper-case drive letters on Windows systems. + * @since 4.5.0 Allows for Windows network shares. * * @param string $path Path to normalize. * @return string Normalized path. */ function wp_normalize_path( $path ) { $path = str_replace( '\\', '/', $path ); - $path = preg_replace( '|/+|','/', $path ); + $path = preg_replace( '|(?<=.)/+|', '/', $path ); if ( ':' === substr( $path, 1, 1 ) ) { $path = ucfirst( $path ); } diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php index 8ee3e8de20..0ac1484c93 100644 --- a/tests/phpunit/tests/file.php +++ b/tests/phpunit/tests/file.php @@ -175,4 +175,26 @@ class Tests_File extends WP_UnitTestCase { ); } + /** + * @dataProvider data_wp_normalize_path + */ + function test_wp_normalize_path( $path, $expected ) { + $this->assertEquals( $expected, wp_normalize_path( $path ) ); + } + function data_wp_normalize_path() { + return array( + // Windows paths + array( 'C:\\www\\path\\', 'C:/www/path/' ), + array( 'C:\\www\\\\path\\', 'C:/www/path/' ), + array( 'c:/www/path', 'C:/www/path' ), + array( 'c:\\www\\path\\', 'C:/www/path/' ), // uppercase drive letter + array( '\\\\Domain\\DFSRoots\\share\\path\\', '//Domain/DFSRoots/share/path/' ), + array( '\\\\Server\\share\\path', '//Server/share/path' ), + + // Linux paths + array( '/www/path/', '/www/path/' ), + array( '/www/path/////', '/www/path/' ), + array( '/www/path', '/www/path' ), + ); + } }