[wp-trac] [WordPress Trac] #57242: Remove redundant dot in sanitize_file_name function

WordPress Trac noreply at wordpress.org
Sat Dec 3 13:57:04 UTC 2022


#57242: Remove redundant dot in sanitize_file_name function
-------------------------+---------------------
 Reporter:  ArtZ91       |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.2
Component:  Formatting   |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |     Focuses:
-------------------------+---------------------
Changes (by SergeyBiryukov):

 * keywords:  has-patch 2nd-opinion => needs-patch
 * milestone:  Awaiting Review => 6.2


Comment:

 Replying to [comment:5 costdev]:
 > We could:
 >
 > 1. Replace all instances of `..` (or more) with `.` (or `-`, etc)
 > 2. Apply `rtrim( $filename, '.' )`.
 > 3. Append the extension.

 Thanks! That makes sense to me. Seems similar to what
 [source:tags/6.1.1/src/wp-
 includes/formatting.php?marks=2368,2372,2373#L2366
 sanitize_title_with_dashes()] does:
 1. It replaces all `.` characters with `-`:
 {{{
 $title = str_replace( '.', '-', $title );
 }}}
 2. Then it replaces multiple instances with a single one:
 {{{
 $title = preg_replace( '|-+|', '-', $title );
 }}}
 3. Then removes leading and trailing instances:
 {{{
 $title = trim( $title, '-' );
 }}}

 It looks like `sanitize_file_name()` [source:tags/6.1.1/src/wp-
 includes/formatting.php?marks=2050,2051#L2047 already does steps 2 and 3],
 though perhaps too early, before the file name is separated from the
 extension.

 So it might be a good idea to apply these steps to file names too.

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


More information about the wp-trac mailing list