Filesystem: Allow `wp_normalise_path()` to handle PHP stream wrappers such as `php://` correctly.
Props calin, dd32. Fixes #42837. git-svn-id: https://develop.svn.wordpress.org/trunk@42387 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f8dbb79a13
commit
da689558a5
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -150,6 +150,11 @@ class Tests_Functions extends WP_UnitTestCase {
|
|||
array( '/www/path/', '/www/path/' ),
|
||||
array( '/www/path/////', '/www/path/' ),
|
||||
array( '/www/path', '/www/path' ),
|
||||
|
||||
// PHP Stream wrappers
|
||||
array( 'php://input', 'php://input' ),
|
||||
array( 'http://example.com//path.ext', 'http://example.com/path.ext' ),
|
||||
array( 'file://c:\\www\\path\\', 'file://C:/www/path/' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue