Make WordPress Core


Ignore:
Timestamp:
04/29/2020 03:38:43 PM (6 years ago)
Author:
whyisjake
Message:

Formatting: Expand sanitize_file_name to have better support for utf8 characters.

Props: xknown, peterwilsoncc.

File:
1 edited

Legend:

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

    r47550 r47638  
    20062006        $filename_raw  = $filename;
    20072007        $special_chars = array( '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', chr( 0 ) );
     2008
     2009        // Check for support for utf8 in the installed PCRE library once and store the result in a static.
     2010        static $utf8_pcre = null;
     2011        if ( ! isset( $utf8_pcre ) ) {
     2012                // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
     2013                $utf8_pcre = @preg_match( '/^./u', 'a' );
     2014        }
     2015
     2016        if ( ! seems_utf8( $filename ) ) {
     2017                $_ext     = pathinfo( $filename, PATHINFO_EXTENSION );
     2018                $_name    = pathinfo( $filename, PATHINFO_FILENAME );
     2019                $filename = sanitize_title_with_dashes( $_name ) . '.' . $_ext;
     2020        }
     2021
     2022        if ( $utf8_pcre ) {
     2023                $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
     2024        }
     2025
    20082026        /**
    20092027         * Filters the list of characters to remove from a filename.
     
    20152033         */
    20162034        $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
    2017         $filename      = preg_replace( "#\x{00a0}#siu", ' ', $filename );
    20182035        $filename      = str_replace( $special_chars, '', $filename );
    20192036        $filename      = str_replace( array( '%20', '+' ), '-', $filename );
Note: See TracChangeset for help on using the changeset viewer.