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
This commit is contained in:
parent
4f16590e8e
commit
89d1eb1e00
|
@ -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.
|
// Check for both lower and upper case extension or image sub-sizes may be overwritten.
|
||||||
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
|
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
|
||||||
$new_number = $number + 1;
|
$new_number = $number + 1;
|
||||||
$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
|
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
|
||||||
$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
|
$filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
|
||||||
$number = $new_number;
|
$number = $new_number;
|
||||||
}
|
}
|
||||||
return $filename2;
|
return $filename2;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( file_exists( $dir . "/$filename" ) ) {
|
while ( file_exists( $dir . "/$filename" ) ) {
|
||||||
if ( '' == "$number$ext" )
|
if ( '' == "$number$ext" ) {
|
||||||
$filename = $filename . ++$number . $ext;
|
$filename = "$filename-" . ++$number;
|
||||||
else
|
} else {
|
||||||
$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
|
$filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue