Skip to content
Permalink
Browse files

Media: Fix deletion of files on Windows.

`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 fe2b4ee0d930ece99c2dda9ca2966860a8e3d2ca
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/wp-includes/functions.php
@@ -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;
}

0 comments on commit fe2b4ee

Please sign in to comment.
You can’t perform that action at this time.