diff --git a/libraries/joomla/filesystem/file.php b/libraries/joomla/filesystem/file.php index 01e728bbb4fb4..8632b8c852550 100644 --- a/libraries/joomla/filesystem/file.php +++ b/libraries/joomla/filesystem/file.php @@ -65,7 +65,10 @@ public static function makeSafe($file) // Remove any trailing dots, as those aren't ever valid file names. $file = rtrim($file, '.'); - $regex = array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#', '#^\.#'); + // Allow uploading UTF-8 filenames in Windows starting from PHP 7.1 and other OS + $unicode = strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || version_compare(PHP_VERSION, '7.1', '>=') ? 'u' : ''; + + $regex = array('#(\.){2,}#', '#[^\w\.\- ]#' . $unicode, '#^\.#'); return trim(preg_replace($regex, '', $file)); } diff --git a/libraries/joomla/filesystem/folder.php b/libraries/joomla/filesystem/folder.php index 178f0eb4d58e0..16f77768e4c7d 100644 --- a/libraries/joomla/filesystem/folder.php +++ b/libraries/joomla/filesystem/folder.php @@ -715,7 +715,10 @@ public static function listFolderTree($path, $filter, $maxLevel = 3, $level = 0, */ public static function makeSafe($path) { - $regex = array('#[^A-Za-z0-9_\\\/\(\)\[\]\{\}\#\$\^\+\.\'~`!@&=;,-]#'); + // Allow uploading UTF-8 filenames in Windows starting from PHP 7.1 and other OS + $unicode = strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || version_compare(PHP_VERSION, '7.1', '>=') ? 'u' : ''; + + $regex = array('#[^\w\\\/\(\)\[\]\{\}\#\$\^\+\.\'~`!@&=;,-]#' . $unicode); return preg_replace($regex, '', $path); }