WordPress.org

Make WordPress Core

Ticket #11218: 11218.patch

File 11218.patch, 1.4 KB (added by azaozz, 8 years ago)

Convert extensions to lower case when possible

  • wp-includes/functions.php

     
    21052105
    21062106        // separate the filename into a name and extension
    21072107        $info = pathinfo($filename);
    2108         $ext = !empty($info['extension']) ? $info['extension'] : '';
    2109         $name = basename($filename, ".{$ext}");
     2108        $ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
     2109        $name = basename($filename, $ext);
    21102110
    21112111        // edge case: if file is named '.ext', treat as an empty name
    2112         if( $name === ".$ext" )
     2112        if( $name === $ext )
    21132113                $name = '';
    21142114
    21152115        // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
     
    21182118        } else {
    21192119                $number = '';
    21202120
    2121                 if ( !empty( $ext ) )
    2122                         $ext = ".$ext";
     2121                // change '.ext' to lower case
     2122                if ( $ext && strtolower($ext) != $ext ) {
     2123                        // make sure there's no file with the upper case extension or image sub-sizes may be overwritten
     2124                        while ( file_exists( $dir . "/$filename" ) ) {
     2125                                $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
     2126                        }
    21232127
     2128                        $ext = strtolower($ext);
     2129                        $filename = preg_replace( '|\.' . preg_quote($info['extension']) . '$|', $ext, $filename );
     2130                }
     2131
    21242132                while ( file_exists( $dir . "/$filename" ) ) {
    21252133                        if ( '' == "$number$ext" )
    21262134                                $filename = $filename . ++$number . $ext;