Skip to content

Commit

Permalink
Media: Fix deletion of files on Windows.
Browse files Browse the repository at this point in the history
`wp_delete_file_from_directory()` should always normalize file paths before comparing.

Props tonybogdanov, SergeyBiryukov.
Merges [45352] to the 5.2 branch.
Fixes #47185.

git-svn-id: https://develop.svn.wordpress.org/branches/5.2@45353 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 17, 2019
1 parent ef60679 commit fe2b4ee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/wp-includes/functions.php
Expand Up @@ -6282,13 +6282,21 @@ function wp_delete_file( $file ) {
*/
function wp_delete_file_from_directory( $file, $directory ) {
if ( wp_is_stream( $file ) ) {
$real_file = wp_normalize_path( $file );
$real_directory = wp_normalize_path( $directory );
$real_file = $file;
$real_directory = $directory;
} else {
$real_file = realpath( wp_normalize_path( $file ) );
$real_directory = realpath( wp_normalize_path( $directory ) );
}

if ( false !== $real_file ) {
$real_file = wp_normalize_path( $real_file );
}

if ( false !== $real_directory ) {
$real_directory = wp_normalize_path( $real_directory );
}

if ( false === $real_file || false === $real_directory || strpos( $real_file, trailingslashit( $real_directory ) ) !== 0 ) {
return false;
}
Expand Down

0 comments on commit fe2b4ee

Please sign in to comment.