Ticket #9416: 9416.2.diff
| File 9416.2.diff, 3.3 KB (added by sivel, 4 years ago) |
|---|
-
wp-includes/functions.php
2011 2011 * @return string New filename, if given wasn't unique. 2012 2012 */ 2013 2013 function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) { 2014 $filename = strtolower( $filename ); 2014 // sanitize the file name before we begin processing 2015 $filename = sanitize_file_name($filename); 2016 2015 2017 // separate the filename into a name and extension 2016 2018 $info = pathinfo($filename); 2017 2019 $ext = !empty($info['extension']) ? $info['extension'] : ''; 2018 2020 $name = basename($filename, ".{$ext}"); 2019 2021 2020 2022 // edge case: if file is named '.ext', treat as an empty name 2021 2023 if( $name === ".$ext" ) 2022 2024 $name = ''; … … 2028 2030 $number = ''; 2029 2031 2030 2032 if ( !empty( $ext ) ) 2031 $ext = strtolower( ".$ext" );2033 $ext = ".$ext"; 2032 2034 2033 $filename = str_replace( $ext, '', $filename );2034 // Strip % so the server doesn't try to decode entities.2035 $filename = str_replace('%', '', sanitize_title_with_dashes( $filename ) ) . $ext;2036 2037 2035 while ( file_exists( $dir . "/$filename" ) ) { 2038 2036 if ( '' == "$number$ext" ) 2039 2037 $filename = $filename . ++$number . $ext; -
wp-includes/formatting.php
564 564 } 565 565 566 566 /** 567 * Filters certain characters from the file name.567 * Sanitizes a filename replacing whitespace with dashes 568 568 * 569 * Turns all strings to lowercase removing most characters except alphanumeric 570 * with spaces, dashes and periods. All spaces and underscores are converted to 571 * dashes. Multiple dashes are converted to a single dash. Finally, if the file 572 * name ends with a dash, it is removed. 569 * Removes special characters that are illegal in filenames on certain 570 * operating systems and special characters requiring special escaping 571 * to manipulate at the command line. Replaces spaces and consecutive 572 * dashes with a single dash. Trim period, dash and underscore from beginning 573 * and end of filename. 573 574 * 574 575 * @since 2.1.0 575 576 * 576 * @param string $ name The file name577 * @return string Sanitized filename577 * @param string $filename The filename to be sanitized 578 * @return string The sanitized filename 578 579 */ 579 function sanitize_file_name( $name ) { // Like sanitize_title, but with periods 580 $name = strtolower( $name ); 581 $name = preg_replace('/&.+?;/', '', $name); // kill entities 582 $name = str_replace( '_', '-', $name ); 583 $name = preg_replace('/[^a-z0-9\s-.]/', '', $name); 584 $name = preg_replace('/\s+/', '-', $name); 585 $name = preg_replace('|-+|', '-', $name); 586 $name = trim($name, '-'); 587 return $name; 580 function sanitize_file_name( $filename ) { 581 $filename_raw = $filename; 582 $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}"); 583 $special_chars = apply_filters('sanitize_file_name_chars', $special_chars, $filename_raw); 584 $filename = str_replace($special_chars, '', $filename); 585 $filename = preg_replace('(\s+|-+)', '-', $filename); 586 $filename = trim($filename, '.-_'); 587 return apply_filters('sanitize_file_name', $filename, $filename_raw); 588 588 } 589 589 590 590 /**
