WordPress.org

Make WordPress Core

Ticket #48975: 48975.diff

File 48975.diff, 2.1 KB (added by azaozz, 3 months ago)
  • src/wp-includes/functions.php

     
    24102410function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
    24112411        // Sanitize the file name before we begin processing.
    24122412        $filename = sanitize_file_name( $filename );
     2413        $ext2     = null;
    24132414
    24142415        // Separate the filename into a name and extension.
    24152416        $ext  = pathinfo( $filename, PATHINFO_EXTENSION );
     
    24792480                        $files = array_diff( scandir( $dir ), array( '.', '..' ) );
    24802481
    24812482                        if ( ! empty( $files ) ) {
     2483                                // The extension case may have changed above.
     2484                                $new_ext = ! empty( $ext2 ) ? $ext2 : $ext;
     2485
    24822486                                while ( _wp_check_existing_file_names( $filename, $files ) ) {
    24832487                                        $new_number = (int) $number + 1;
    2484                                         $filename   = str_replace( array( "-{$number}{$ext}", "{$number}{$ext}" ), "-{$new_number}{$ext}", $filename );
     2488                                        $filename   = str_replace( array( "-{$number}{$new_ext}", "{$number}{$new_ext}" ), "-{$new_number}{$new_ext}", $filename );
    24852489                                        $number     = $new_number;
    24862490                                }
    24872491                        }
     
    25242528                $ext = ".$ext";
    25252529        }
    25262530
    2527         $regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/';
     2531        $regex = '/^' . preg_quote( $fname ) . '-(?:\d+x\d+|scaled|rotated)' . preg_quote( $ext ) . '$/i';
    25282532
    25292533        foreach ( $files as $file ) {
    25302534                if ( preg_match( $regex, $file ) ) {
  • tests/phpunit/tests/functions.php

     
    206206                // Test collision with existing sub-size filename.
    207207                // Existing files: one-blue-pixel-100x100.png, one-blue-pixel-1-100x100.png.
    208208                $this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.png' ) );
     209                // Same as above with upper case extension.
     210                $this->assertEquals( 'one-blue-pixel-2.png', wp_unique_filename( $testdir, 'one-blue-pixel.PNG' ) );
    209211        }
    210212
    211213        function test_is_serialized() {