WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/06/2019 10:26:19 PM (2 years ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r46586 r46822  
    194194        $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\fg.png' ), 'Double slashed not removed' );
    195195        $this->assertEquals( 'abcdefg.png', wp_unique_filename( $testdir, 'abcde\\\fg.png' ), 'Tripple slashed not removed' );
     196    }
     197
     198    /**
     199     * @group 42437
     200     */
     201    function test_unique_filename_with_dimension_like_filename() {
     202        $testdir = DIR_TESTDATA . '/images/';
     203
     204        // Test collision with "dimension-like" original filename.
     205        $this->assertEquals( 'one-blue-pixel-100x100-1.png', wp_unique_filename( $testdir, 'one-blue-pixel-100x100.png' ) );
     206        // Test collision with existing sub-size filename.
     207        // Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png.
     208        $this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) );
    196209    }
    197210
Note: See TracChangeset for help on using the changeset viewer.