[wp-trac] [WordPress Trac] #39791: sanitize_file_name() optimizations
WordPress Trac
noreply at wordpress.org
Mon Feb 6 23:44:06 UTC 2017
#39791: sanitize_file_name() optimizations
-------------------------+------------------------------
Reporter: mgutt | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by mgutt):
This one should be added as well:
{{{
// maximum filename length of 255 bytes
http://serverfault.com/a/9548/44086
// note: mb_strcut() relies as strlen() on bytes and not chars
if ($ext = pathinfo($filename, PATHINFO_EXTENSION)) {
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0,
255 - strlen($ext) - 1, mb_detect_encoding($filename)) . '.' . $ext;
}
else {
$filename = mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0,
255, mb_detect_encoding($filename));
}
}}}
But it should be executed at the end after all the filename changes have
been done (removing whitespace, removing consecutive characters, etc.) so
it contains as much as possible before we cut it.
Could be added, too:
{{{
// lowercase for better windows/unix interoperability
http://support.microsoft.com/kb/100625
$filename = mb_strtolower($filename, mb_detect_encoding($filename));
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39791#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list