Fix incorrect encoding of filenames with single quotes

This commit is contained in:
Kijin Sung 2024-10-09 15:37:22 +09:00
parent 0a92627c8a
commit 44608bbe90
2 changed files with 7 additions and 7 deletions

View file

@ -15,6 +15,9 @@ class FilenameFilter
*/
public static function clean(string $filename): string
{
// Clean up unnecessary encodings.
$filename = strtr($filename, ['&' => '&', ''' => "'"]);
// Replace dangerous characters with safe alternatives, maintaining meaning as much as possible.
$illegal = array('\\', '/', '<', '>', '{', '}', ':', ';', '|', '"', '~', '`', '$', '%', '^', '*', '?');
$replace = array('', '', '(', ')', '(', ')', '_', ',', '_', '', '_', '\'', '_', '_', '_', '', '');
@ -31,9 +34,6 @@ class FilenameFilter
$filename = preg_replace('/__+/', '_', $filename);
$filename = preg_replace('/\.\.+/', '.', $filename);
// Clean up unnecessary encodings.
$filename = strtr($filename, array('&amp;' => '&'));
// Change .php files to .phps to make them non-executable.
if (strtolower(substr($filename, strlen($filename) - 4)) === '.php')
{