[wp-trac] [WordPress Trac] #54078: Underscore appended to media file on upload

WordPress Trac noreply at wordpress.org
Tue Sep 7 14:35:04 UTC 2021


#54078: Underscore appended to media file on upload
---------------------------+------------------------------
 Reporter:  spielautomat4  |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Upload         |     Version:  5.8
 Severity:  normal         |  Resolution:
 Keywords:  dev-feedback   |     Focuses:  administration
---------------------------+------------------------------
Changes (by karpstrucking):

 * keywords:  reporter-feedback => dev-feedback


Comment:

 It looks like this is actually an intended function of
 `sanitize_file_name()`
 (https://core.trac.wordpress.org/browser/tags/5.8/src/wp-
 includes/formatting.php#L2047)


 {{{
         /*
          * Loop over any intermediate extensions. Postfix them with a
 trailing underscore
          * if they are a 2 - 5 character long alpha string not in the
 allowed extension list.
          */
         foreach ( (array) $parts as $part ) {
                 $filename .= '.' . $part;

                 if ( preg_match( '/^[a-zA-Z]{2,5}\d?$/', $part ) ) {
                         $allowed = false;
                         foreach ( $mimes as $ext_preg => $mime_match ) {
                                 $ext_preg = '!^(' . $ext_preg . ')$!i';
                                 if ( preg_match( $ext_preg, $part ) ) {
                                         $allowed = true;
                                         break;
                                 }
                         }
                         if ( ! $allowed ) {
                                 $filename .= '_';
                         }
                 }
         }

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54078#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list