WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/21/2016 01:43:59 PM (4 years ago)
Author:
joemcgill
Message:

Media: Improve handling of extensionless filenames.

This ensures files retain a filename after sanitization.

Fixes 37111.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r37747 r37756  
    17261726 * to manipulate at the command line. Replaces spaces and consecutive
    17271727 * dashes with a single dash. Trims period, dash and underscore from beginning
    1728  * and end of filename.
     1728 * and end of filename. It is not guaranteed that this function will return a
     1729 * filename that is allowed to be uploaded.
    17291730 *
    17301731 * @since 2.1.0
     
    17501751    $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename );
    17511752    $filename = trim( $filename, '.-_' );
     1753
     1754    if ( false === strpos( $filename, '.' ) ) {
     1755        $mime_types = wp_get_mime_types();
     1756        $filetype = wp_check_filetype( 'test.' . $filename, $mime_types );
     1757        if ( $filetype['ext'] === $filename ) {
     1758            $filename = 'unnamed-file.' . $filetype['ext'];
     1759        }
     1760    }
    17521761
    17531762    // Split the filename into a base and extension[s]
Note: See TracChangeset for help on using the changeset viewer.