Project

General

Profile

Bug #19944 » bug10313-trunk.patch

Administrator Admin, 2009-02-27 12:21

View differences:

t3lib/class.t3lib_basicfilefunc.php (working copy)
/**
* Returns a string where any character not matching [.a-zA-Z0-9_-] is substituted by '_'
* Trailing dots are removed
*
* @param string Input string, typically the body of a filename
* @param string Charset of the a filename (defaults to current charset; depending on context)
* @return string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_'
* @return string Output string with any characters not matching [.a-zA-Z0-9_-] is substituted by '_' and trailing dots removed
*/
function cleanFileName($fileName,$charset='') {
// handle UTF-8 characters
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] == 'utf-8' && $GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
function cleanFileName($fileName, $charset = '') {
// Handle UTF-8 characters
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] == 'utf-8' && $GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
// allow ".", "-", 0-9, a-z, A-Z and everything beyond U+C0 (latin capital letter a with grave)
return preg_replace('/[\x00-\x2C\/\x3A-\x3F\x5B-\x60\x7B-\xBF]/u','_',trim($fileName));
}
$cleanFileName = preg_replace('/[\x00-\x2C\/\x3A-\x3F\x5B-\x60\x7B-\xBF]/u', '_', trim($fileName));
if (!is_object($this->csConvObj)) {
if (TYPO3_MODE=='FE') {
$this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
} elseif (is_object($GLOBALS['LANG'])) { // BE assumed:
$this->csConvObj = &$GLOBALS['LANG']->csConvObj;
} else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
$this->csConvObj = &t3lib_div::makeInstance('t3lib_cs');
// Handle other character sets
} else {
// Get conversion object or initialize if needed
if (!is_object($this->csConvObj)) {
if (TYPO3_MODE=='FE') {
$this->csConvObj = &$GLOBALS['TSFE']->csConvObj;
} elseif (is_object($GLOBALS['LANG'])) { // BE assumed:
$this->csConvObj = &$GLOBALS['LANG']->csConvObj;
} else { // The object may not exist yet, so we need to create it now. Happens in the Install Tool for example.
$this->csConvObj = &t3lib_div::makeInstance('t3lib_cs');
}
}
}
if (!$charset) {
if (TYPO3_MODE=='FE') {
$charset = $GLOBALS['TSFE']->renderCharset;
} elseif (is_object($GLOBALS['LANG'])) { // BE assumed:
$charset = $GLOBALS['LANG']->charSet;
} else { // best guess
$charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
// Define character set
if (!$charset) {
if (TYPO3_MODE == 'FE') {
$charset = $GLOBALS['TSFE']->renderCharset;
} elseif (is_object($GLOBALS['LANG'])) { // BE assumed:
$charset = $GLOBALS['LANG']->charSet;
} else { // best guess
$charset = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
}
}
}
if ($charset) {
$fileName = $this->csConvObj->specCharsToASCII($charset,$fileName);
// If a charset was found, convert filename
if ($charset) {
$fileName = $this->csConvObj->specCharsToASCII($charset, $fileName);
}
// Replace unwanted characters by underscores
$cleanFileName = preg_replace('/[^.[:alnum:]_-]/', '_', trim($fileName));
}
$fileName = preg_replace('/[^.[:alnum:]_-]/','_',trim($fileName));
return preg_replace('/\.*$/','',$fileName);
// Strip trailing dots and return
return preg_replace('/\.*$/', '', $cleanFileName);
}
/**
(3-3/3)