Make WordPress Core

Ticket #35996: 35996.diff

File 35996.diff, 3.1 KB (added by dd32, 8 years ago)
  • src/wp-includes/functions.php

    function path_is_absolute( $path ) { 
    16751675 * @param string $path Path relative to $base.
    16761676 * @return string The path with the base or absolute path.
    16771677 */
    16781678function path_join( $base, $path ) {
    16791679        if ( path_is_absolute($path) )
    16801680                return $path;
    16811681
    16821682        return rtrim($base, '/') . '/' . ltrim($path, '/');
    16831683}
    16841684
    16851685/**
    16861686 * Normalize a filesystem path.
    16871687 *
    16881688 * On windows systems, replaces backslashes with forward slashes
    16891689 * and forces upper-case drive letters.
    1690  * Ensures that no duplicate slashes exist.
     1690 * Allows for two leading slashes for Windows network shares, but
     1691 * ensures that all other duplicate slashes are reduced to a single.
    16911692 *
    16921693 * @since 3.9.0
    16931694 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
     1695 * @since 4.5.0 Allows for Windows network shares.
    16941696 *
    16951697 * @param string $path Path to normalize.
    16961698 * @return string Normalized path.
    16971699 */
    16981700function wp_normalize_path( $path ) {
    16991701        $path = str_replace( '\\', '/', $path );
    1700         $path = preg_replace( '|/+|','/', $path );
     1702        $path = preg_replace( '|(?<=.)/+|', '/', $path );
    17011703        if ( ':' === substr( $path, 1, 1 ) ) {
    17021704                $path = ucfirst( $path );
    17031705        }
    17041706        return $path;
    17051707}
    17061708
    17071709/**
    17081710 * Determine a writable directory for temporary files.
    17091711 *
    17101712 * Function's preference is the return value of sys_get_temp_dir(),
    17111713 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR,
    17121714 * before finally defaulting to /tmp/
    17131715 *
    17141716 * In the event that this function does not find a writable location,
    17151717 * It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.
  • tests/phpunit/tests/file.php

    class Tests_File extends WP_UnitTestCase 
    163163                unlink( $file );
    164164
    165165                $this->assertNotEmpty( basename( basename( $file, '.tmp' ), '.zip' ) );
    166166        }
    167167        function data_wp_tempnam_filenames() {
    168168                return array(
    169169                        array( '0.zip' ),
    170170                        array( '0.1.2.3.zip' ),
    171171                        array( 'filename.zip' ),
    172172                        array( 'directory/0.zip' ),
    173173                        array( 'directory/filename.zip' ),
    174174                        array( 'directory/0/0.zip' ),
    175175                );
    176176        }
    177177
     178        /**
     179         * @dataProvider data_wp_normalize_path
     180         */
     181        function test_wp_normalize_path( $path, $expected ) {
     182                $this->assertEquals( $expected, wp_normalize_path( $path ) );
     183        }
     184        function data_wp_normalize_path() {
     185                return array(
     186                        // Windows paths
     187                        array( 'C:\\www\\path\\', 'C:/www/path/' ),
     188                        array( 'C:\\www\\\\path\\', 'C:/www/path/' ),
     189                        array( 'c:/www/path', 'C:/www/path' ),
     190                        array( 'c:\\www\\path\\', 'C:/www/path/' ), // uppercase drive letter
     191                        array( '\\\\Domain\\DFSRoots\\share\\path\\', '//Domain/DFSRoots/share/path/' ),
     192                        array( '\\\\Server\\share\\path', '//Server/share/path' ),
     193
     194                        // Linux paths
     195                        array( '/www/path/', '/www/path/' ),
     196                        array( '/www/path/////', '/www/path/' ),
     197                        array( '/www/path', '/www/path' ),
     198                );
     199        }
    178200}