Upload: fix wp_unique_filename() to prevent name collisions with existing or future image sub-size file names, and add unit tests.

Props Viper007Bond, pbiron, azaozz.
Fixes #42437.

git-svn-id: https://develop.svn.wordpress.org/trunk@46822 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2019-12-06 22:26:19 +00:00
parent bcfccc7344
commit 5464dcb2c5
3 changed files with 97 additions and 22 deletions
+13
View File
@@ -195,6 +195,19 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' );
}
/**
* @group 42437
*/
function test_unique_filename_with_dimension_like_filename() {
$testdir = DIR_TESTDATA . '/images/';
// Test collision with "dimension-like" original filename.
$this->assertEquals( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) );
// Test collision with existing sub-size filename.
// Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png.
$this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) );
}
function test_is_serialized() {
$cases = array(
serialize( null ),