Ticket #35996: 35996.diff
File 35996.diff, 3.1 KB (added by , 8 years ago) |
---|
-
src/wp-includes/functions.php
function path_is_absolute( $path ) { 1675 1675 * @param string $path Path relative to $base. 1676 1676 * @return string The path with the base or absolute path. 1677 1677 */ 1678 1678 function path_join( $base, $path ) { 1679 1679 if ( path_is_absolute($path) ) 1680 1680 return $path; 1681 1681 1682 1682 return rtrim($base, '/') . '/' . ltrim($path, '/'); 1683 1683 } 1684 1684 1685 1685 /** 1686 1686 * Normalize a filesystem path. 1687 1687 * 1688 1688 * On windows systems, replaces backslashes with forward slashes 1689 1689 * 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. 1691 1692 * 1692 1693 * @since 3.9.0 1693 1694 * @since 4.4.0 Ensures upper-case drive letters on Windows systems. 1695 * @since 4.5.0 Allows for Windows network shares. 1694 1696 * 1695 1697 * @param string $path Path to normalize. 1696 1698 * @return string Normalized path. 1697 1699 */ 1698 1700 function wp_normalize_path( $path ) { 1699 1701 $path = str_replace( '\\', '/', $path ); 1700 $path = preg_replace( '| /+|','/', $path );1702 $path = preg_replace( '|(?<=.)/+|', '/', $path ); 1701 1703 if ( ':' === substr( $path, 1, 1 ) ) { 1702 1704 $path = ucfirst( $path ); 1703 1705 } 1704 1706 return $path; 1705 1707 } 1706 1708 1707 1709 /** 1708 1710 * Determine a writable directory for temporary files. 1709 1711 * 1710 1712 * Function's preference is the return value of sys_get_temp_dir(), 1711 1713 * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, 1712 1714 * before finally defaulting to /tmp/ 1713 1715 * 1714 1716 * In the event that this function does not find a writable location, 1715 1717 * 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 163 163 unlink( $file ); 164 164 165 165 $this->assertNotEmpty( basename( basename( $file, '.tmp' ), '.zip' ) ); 166 166 } 167 167 function data_wp_tempnam_filenames() { 168 168 return array( 169 169 array( '0.zip' ), 170 170 array( '0.1.2.3.zip' ), 171 171 array( 'filename.zip' ), 172 172 array( 'directory/0.zip' ), 173 173 array( 'directory/filename.zip' ), 174 174 array( 'directory/0/0.zip' ), 175 175 ); 176 176 } 177 177 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 } 178 200 }