Changeset 43399 for branches/4.3/src/wp-includes/functions.php
- Timestamp:
- 07/05/2018 03:02:04 PM (8 years ago)
- File:
-
- 1 edited
-
branches/4.3/src/wp-includes/functions.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.3/src/wp-includes/functions.php
r42291 r43399 1591 1591 * Normalize a filesystem path. 1592 1592 * 1593 * Replaces backslashes with forward slashes for Windows systems, and ensures 1594 * no duplicate slashes exist. 1593 * On windows systems, replaces backslashes with forward slashes 1594 * and forces upper-case drive letters. 1595 * Allows for two leading slashes for Windows network shares, but 1596 * ensures that all other duplicate slashes are reduced to a single. 1595 1597 * 1596 1598 * @since 3.9.0 1599 * @since 4.4.0 Ensures upper-case drive letters on Windows systems. 1600 * @since 4.5.0 Allows for Windows network shares. 1601 * @since 4.9.7 Allows for PHP file wrappers. 1597 1602 * 1598 1603 * @param string $path Path to normalize. … … 1600 1605 */ 1601 1606 function wp_normalize_path( $path ) { 1607 $wrapper = ''; 1608 if ( wp_is_stream( $path ) ) { 1609 list( $wrapper, $path ) = explode( '://', $path, 2 ); 1610 $wrapper .= '://'; 1611 } 1612 1613 // Standardise all paths to use / 1602 1614 $path = str_replace( '\\', '/', $path ); 1603 $path = preg_replace( '|/+|','/', $path ); 1604 return $path; 1615 1616 // Replace multiple slashes down to a singular, allowing for network shares having two slashes. 1617 $path = preg_replace( '|(?<=.)/+|', '/', $path ); 1618 1619 // Windows paths should uppercase the drive letter 1620 if ( ':' === substr( $path, 1, 1 ) ) { 1621 $path = ucfirst( $path ); 1622 } 1623 1624 return $wrapper . $path; 1605 1625 } 1606 1626 … … 5010 5030 5011 5031 /** 5032 * Deletes a file if its path is within the given directory. 5033 * 5034 * @since 4.9.7 5035 * 5036 * @param string $file Absolute path to the file to delete. 5037 * @param string $directory Absolute path to a directory. 5038 * @return bool True on success, false on failure. 5039 */ 5040 function wp_delete_file_from_directory( $file, $directory ) { 5041 $real_file = realpath( wp_normalize_path( $file ) ); 5042 $real_directory = realpath( wp_normalize_path( $directory ) ); 5043 5044 if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) { 5045 return false; 5046 } 5047 5048 wp_delete_file( $file ); 5049 5050 return true; 5051 } 5052 5053 /** 5012 5054 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload. 5013 5055 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)