From 89d1eb1e0034d6917b0f2e7e5c7d5be2513550ac Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 20 Oct 2015 04:05:25 +0000 Subject: [PATCH] Formatting: when making unique filenames in `wp_unique_filename()` by adding an incrementing number, prefix it with a dash to disambiguate from files that end in numbers. Updates unit tests. Props mikejolley, tyxla. Fixes #21453. Built from https://develop.svn.wordpress.org/trunk@35276 git-svn-id: http://core.svn.wordpress.org/trunk@35242 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 13 +++++++------ wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 8989026c22..67386aaa3c 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1918,18 +1918,19 @@ function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) // Check for both lower and upper case extension or image sub-sizes may be overwritten. while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) { $new_number = $number + 1; - $filename = str_replace( "$number$ext", "$new_number$ext", $filename ); - $filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 ); + $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename ); + $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 ); $number = $new_number; } return $filename2; } while ( file_exists( $dir . "/$filename" ) ) { - if ( '' == "$number$ext" ) - $filename = $filename . ++$number . $ext; - else - $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); + if ( '' == "$number$ext" ) { + $filename = "$filename-" . ++$number; + } else { + $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename ); + } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 966a1a62f3..31dcbf608e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-35275'; +$wp_version = '4.4-alpha-35276'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.