- Fix PHP warnings in `wp_unique_filename()` when the destination directory is unreadable.
- Run the final name collision test only for files that are saved to the uploads directory.
- Update the unit tests to match.

Props eden159, audrasjb, azaozz.
Fixes #48960 for trunk.
Built from https://develop.svn.wordpress.org/trunk@46965


git-svn-id: http://core.svn.wordpress.org/trunk@46765 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2019-12-16 23:23:06 +00:00
parent 8894c0f1a2
commit e0ace80488
2 changed files with 10 additions and 4 deletions

View File

@ -2472,11 +2472,17 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null )
// Prevent collisions with existing file names that contain dimension-like strings
// (whether they are subsizes or originals uploaded prior to #42437).
$upload_dir = wp_get_upload_dir();
// The (resized) image files would have name and extension, and will be in the uploads dir.
if ( @is_dir( $dir ) && $name && $ext ) {
// List of all files and directories contained in $dir (with the "dot" files removed).
$files = array_diff( scandir( $dir ), array( '.', '..' ) );
if ( $name && $ext && @is_dir( $dir ) && false !== strpos( $dir, $upload_dir['basedir'] ) ) {
// List of all files and directories contained in $dir.
$files = @scandir( $dir );
if ( ! empty( $files ) ) {
// Remove "dot" dirs.
$files = array_diff( $files, array( '.', '..' ) );
}
if ( ! empty( $files ) ) {
while ( _wp_check_existing_file_names( $filename, $files ) ) {

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.4-alpha-46964';
$wp_version = '5.4-alpha-46965';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.