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

WordPress Trac noreply at wordpress.org
Sat Dec 3 17:39:26 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:
-------------------------+---------------------

Comment (by costdev):

 Thanks @SergeyBiryukov!

 After taking a closer look at `sanitize_file_name()`, this might be a
 little tricky.

 Where steps 2 and 3 are performed, `$filename` may still include one/more
 extensions. So replacing consecutive `.` with `-` could result in
 `filename-png`.

 -----

 I'm thinking if we replace consecutive `.` with a single `.`, that could
 work.

 It means that `...file....name...png...` would become `.file.name.png.`,
 then the `trim()` you already pointed out would change this to
 `file.name.png`

 **Note**: In reality, `sanitize_file_name()` actually produces
 `file.name_.png` - I believe the `_` is added
 [https://core.trac.wordpress.org/browser/tags/6.1.1/src/wp-
 includes/formatting.php?marks=2092#L2092 here], for some reason.

 -----

 With the above regex, my test datasets pass, and the only failure I get
 for an existing test is:
 - `Tests_Functions::test_wp_unique_filename`
 - "Failed crazy file name"
 - Expected: `'12af34567890 at ..^_qwerty-fghjkl-zx.png'`
 - Actual:   `'12af34567890 at .^_qwerty-fghjkl-zx.png'`

 Which I think we could live with. 😅

 -----

 I'll push up a PR for review along with the above, and leave the existing
 test failure in place as a reference.

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


More information about the wp-trac mailing list