Joomla CMS [#27526] Media manager doesn't support multi-byte characters #997

Closed
wants to merge 1 commit into
from
@@ -53,17 +53,26 @@ public static function stripExt($file)
/**
* Makes file name safe to use
*
- * @param string $file The name of the file [not full path]
+ * @param string $filename The name of the file [not full path]
+ * @param boolean $multibyte Support for multibyte file-name
*
* @return string The sanitised string
*
* @since 11.1
*/
- public static function makeSafe($file)
+ public static function makeSafe($filename, $multibyte = false)
{
- $regex = array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#', '#^\.#');
-
- return preg_replace($regex, '', $file);
+ if ($multibyte)
+ {
+ $search = "/\?%*:|\"<>#;()&;, ";
+ return str_replace(str_split($search), '_', $filename);
pasamio
pasamio Aug 14, 2012 Contributor

Shouldn't we use something that is UTF-8 safe here? Perhaps a preg_replace with the u modifier to ensure we don't clobber parts of multibyte characters?

+ }
+ else
+ {
+ $regex = array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#', '#^\.#');
+ return preg_replace($regex, '', $filename);
+ }
+
}
/**