From 632288748732e955b6d6f4fc25b38f8f79d447b2 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 12 Dec 2017 04:16:47 +0000 Subject: [PATCH] Filesystem: Allow `wp_normalise_path()` to handle PHP stream wrappers such as `php://` correctly. Props calin, dd32. Fixes #42837. Built from https://develop.svn.wordpress.org/trunk@42387 git-svn-id: http://core.svn.wordpress.org/trunk@42216 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 15 ++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 23e04cf504..9b5f292eec 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1764,17 +1764,30 @@ function path_join( $base, $path ) { * @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. + * @since 5.0.0 Allows for PHP file wrappers. * * @param string $path Path to normalize. * @return string Normalized path. */ function wp_normalize_path( $path ) { + $wrapper = ''; + if ( wp_is_stream( $path ) ) { + list( $wrapper, $path ) = explode( '://', $path, 2 ); + $wrapper .= '://'; + } + + // Standardise all paths to use / $path = str_replace( '\\', '/', $path ); + + // Replace multiple slashes down to a singular, allowing for network shares having two slashes. $path = preg_replace( '|(?<=.)/+|', '/', $path ); + + // Windows paths should uppercase the drive letter if ( ':' === substr( $path, 1, 1 ) ) { $path = ucfirst( $path ); } - return $path; + + return $wrapper . $path; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index c25676b90f..53339ebd8f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-42386'; +$wp_version = '5.0-alpha-42387'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.