Ticket #22363: 22363.9.patch
File 22363.9.patch, 5.2 KB (added by , 11 years ago) |
---|
-
src/wp-includes/default-filters.php
177 177 add_filter( 'tiny_mce_before_init', '_mce_set_direction' ); 178 178 add_filter( 'pre_kses', 'wp_pre_kses_less_than' ); 179 179 add_filter( 'sanitize_title', 'sanitize_title_with_dashes', 10, 3 ); 180 add_filter( 'sanitize_file_name', 'remove_accents' ); 180 181 add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 3 ); 181 182 add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood', 10, 3 ); 182 183 add_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 ); -
src/wp-includes/formatting.php
826 826 } 827 827 828 828 /** 829 * Sanitizes a filename, replacing whitespace with dashes.829 * Sanitizes a filename, replacing whitespace and illegal characters with dashes. 830 830 * 831 * Removes special characters that are illegal in filenames on certain 832 * operating systems and special characters requiring special escaping 833 * to manipulate at the command line. Replaces spaces and consecutive 834 * dashes with a single dash. Trims period, dash and underscore from beginning 835 * and end of filename. 831 * Replaces all non-alphabetical, non-decimal characters (including 832 * spaces) with dashes. Strips HTML tags and sanitizes HTML entities. Munges 833 * extraneous file extensions with underscores. Converts the filenames to lowercase 834 * when possible. 836 835 * 836 * If the PCRE UTF-8 extension is available, this function converts all characters 837 * that don't have the Unicode property "Letter" or "Decimal number" to dashes. 838 * 837 839 * @since 2.1.0 838 840 * 839 841 * @param string $filename The filename to be sanitized … … 841 843 */ 842 844 function sanitize_file_name( $filename ) { 843 845 $filename_raw = $filename; 846 847 // Check if PCRE UTF-8 extension is compiled and working. 848 static $pcre_utf8 = null; 849 if ( is_null( $pcre_utf8 ) ) 850 $pcre_utf8 = ( 1 === @preg_match( '`[\p{L}]`u', "\xc3\xa0" ) ); // Try to match "latin small letter a with grave". Returns (int) 1 or (boolean) false. 851 852 $encoding = seems_utf8( $filename ) ? 'UTF-8' : get_bloginfo( 'charset' ); 853 $utf8_modifier = ( $pcre_utf8 && 'UTF-8' == $encoding ) ? 'u' : ''; 854 855 $filename = wp_strip_all_tags( $filename ); 856 857 // Decode all HTML entities available in current encoding and strip the rest 858 $filename = html_entity_decode( $filename, ENT_QUOTES, $encoding ); 859 $filename = preg_replace( "`&[a-zA-Z]{2,8};`$utf8_modifier", '', $filename ); 860 861 // Apply filters before sanitizing to allow custom replacements 862 $filename = apply_filters('sanitize_file_name', $filename, $filename_raw); 863 864 // Convert illegal characters to dashes 844 865 $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0)); 845 866 $special_chars = apply_filters('sanitize_file_name_chars', $special_chars, $filename_raw); 846 $filename = str_replace($special_chars, '', $filename); 847 $filename = preg_replace('/[\s-]+/', '-', $filename); 848 $filename = trim($filename, '.-_'); 867 $strip_characters = preg_quote( implode( '', $special_chars ), '`' ); 868 $filename = preg_replace( "`[$strip_characters]`$utf8_modifier", '-', $filename ); 849 869 870 if ( $pcre_utf8 ) { 871 // Convert everything except letters, decimal numbers, and "." (dot) to dashes if the PCRE UTF-8 extension is available 872 $filename = preg_replace( "`(?!\.)[^\p{L}\p{Nd}]+`$utf8_modifier", '-', $filename ); 873 if ( ! $filename ) // Invalid UTF-8 string or empty 874 return ''; 875 } 876 877 $filename = preg_replace( "`[\s-]+`$utf8_modifier", '-', $filename ); // Check whitespace and multiple dashes 878 $filename = preg_replace( "`-\.`$utf8_modifier", '.', $filename ); // Trim dashes before a dot 879 $filename = trim( $filename, '.-_' ); 880 881 if ( function_exists( 'mb_strtolower' ) ) 882 $filename = mb_strtolower( $filename, mb_detect_encoding( $filename ) ); 883 else if ( ! preg_match( '/[^\x20-\x7f]/', $string ) ) // Only ASCII characters present 884 $filename = strtolower( $filename ); 885 850 886 // Split the filename into a base and extension[s] 851 887 $parts = explode('.', $filename); 852 888 853 889 // Return if only one extension 854 890 if ( count($parts) <= 2 ) 855 return apply_filters('sanitize_file_name', $filename, $filename_raw);891 return $filename; 856 892 857 893 // Process multiple extensions 858 894 $filename = array_shift($parts); … … 864 900 foreach ( (array) $parts as $part) { 865 901 $filename .= '.' . $part; 866 902 867 if ( preg_match(" /^[a-zA-Z]{2,5}\d?$/", $part) ) {903 if ( preg_match("`^[a-zA-Z]{2,5}\d?$`$utf8_modifier", $part) ) { 868 904 $allowed = false; 869 905 foreach ( $mimes as $ext_preg => $mime_match ) { 870 $ext_preg = '!^(' . $ext_preg . ')$!i';906 $ext_preg = "`^($ext_preg)$`i$utf8_modifier"; 871 907 if ( preg_match( $ext_preg, $part ) ) { 872 908 $allowed = true; 873 909 break; … … 879 915 } 880 916 $filename .= '.' . $extension; 881 917 882 return apply_filters('sanitize_file_name', $filename, $filename_raw);918 return $filename; 883 919 } 884 920 885 921 /**