Make WordPress Core

Changeset 42387


Ignore:
Timestamp:
12/12/2017 04:15:54 AM (9 years ago)
Author:
dd32
Message:

Filesystem: Allow wp_normalise_path() to handle PHP stream wrappers such as php:// correctly.

Props calin, dd32.
Fixes #42837.

Location:
trunk
Files:
2 edited

Legend:

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

    r42343 r42387  
    17651765 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
    17661766 * @since 4.5.0 Allows for Windows network shares.
     1767 * @since 5.0.0 Allows for PHP file wrappers.
    17671768 *
    17681769 * @param string $path Path to normalize.
     
    17701771 */
    17711772function wp_normalize_path( $path ) {
     1773        $wrapper = '';
     1774        if ( wp_is_stream( $path ) ) {
     1775                list( $wrapper, $path ) = explode( '://', $path, 2 );
     1776                $wrapper .= '://';
     1777        }
     1778
     1779        // Standardise all paths to use /
    17721780        $path = str_replace( '\\', '/', $path );
     1781
     1782        // Replace multiple slashes down to a singular, allowing for network shares having two slashes.
    17731783        $path = preg_replace( '|(?<=.)/+|', '/', $path );
     1784
     1785        // Windows paths should uppercase the drive letter
    17741786        if ( ':' === substr( $path, 1, 1 ) ) {
    17751787                $path = ucfirst( $path );
    17761788        }
    1777         return $path;
     1789
     1790        return $wrapper . $path;
    17781791}
    17791792
  • trunk/tests/phpunit/tests/functions.php

    r42343 r42387  
    151151                        array( '/www/path/////', '/www/path/' ),
    152152                        array( '/www/path', '/www/path' ),
     153
     154                        // PHP Stream wrappers
     155                        array( 'php://input', 'php://input' ),
     156                        array( 'http://example.com//path.ext', 'http://example.com/path.ext' ),
     157                        array( 'file://c:\\www\\path\\', 'file://C:/www/path/' ),
    153158                );
    154159        }
Note: See TracChangeset for help on using the changeset viewer.