[wp-trac] [WordPress Trac] #63551: Long filenames are truncated by sanitize_file_name()

WordPress Trac noreply at wordpress.org
Mon Jun 9 12:58:32 UTC 2025


#63551: Long filenames are truncated by sanitize_file_name()
--------------------------+-----------------------------
 Reporter:  leedxw        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Upload        |    Version:  6.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Filenames over 112 characters will be truncated on upload.

 It's not clear if this is a php quirk (it occurs under 7.4 and 8.3) or is
 intended but undocumented behaviour.

 https://developer.wordpress.org/reference/functions/sanitize_file_name/
 doesn't mention that long files are truncated.

 Looking at the code, this doesn't seem to be the explicit intent? The
 truncation happens with {{{call_user_func_array()}}}

 {{{
 $ wp shell
 wp> sanitize_file_name("this-file-name-ends-with-s-dot-jpg-and-the-base-
 label-consists-of-121-characters-but-will-get-truncated-
 to-110-characters.jpg");
 => string(114) "this-file-name-ends-with-s-dot-jpg-and-the-base-label-
 consists-of-121-characters-but-will-get-truncated-to-110.jpg"
 wp> sanitize_file_name("this-file-name-ends-with-s-dot-jpg-and-the-base-
 label-consists-of-121-characters-but-will-get-truncated-
 to-110-characters.jpeg");
 => string(115) "this-file-name-ends-with-s-dot-jpg-and-the-base-label-
 consists-of-121-characters-but-will-get-truncated-to-110.jpeg"
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63551>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list