MaxServ / t3ext-fal_s3

S3 driver for FAL
GNU General Public License v2.0
13 stars 10 forks source link

The method sanitizeFileName of Classes/Driver/AmazonS3Driver.php does not respect utf-8 #77

Closed sebastienhupin2 closed 1 year ago

sebastienhupin2 commented 1 year ago

A change to this method to respect the ut8filesytem variable from the $GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']

     /**
     * @param $fileName
     * @param $charset
     * @return string
     * @throws InvalidFileNameException
     */
    public function sanitizeFileName($fileName, $charset = '')
    {
        if ($charset === 'utf-8') {
            $fileName = \Normalizer::normalize((string)$fileName) ?: $fileName;
        }
        // Handle UTF-8 characters
        if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
            // Allow ".", "-", 0-9, a-z, A-Z underscores, dashes, parentheses and spaces and everything beyond U+C0 (latin capital letter a with grave)
            $cleanFileName = (string)preg_replace('/[\\x00-\\x27\\x2A-\\x2C\\/\\x3A-\\x3F\\x5B-\\x60\\x7B-\\xBF]/u', '_', trim($fileName));
        }
        else {
            // Allow letters, numbers, underscores, dashes, dots, parentheses and spaces.
            // Replace all other characters with an underscore.
            $cleanFileName = (string)preg_replace('/[^a-zA-Z0-9\-\._() ]/', '_', trim($fileName));
        }

        $cleanFileName = rtrim($cleanFileName, '.');
        if ($cleanFileName === '') {
            throw new InvalidFileNameException(
                'File name ' . $fileName . ' is invalid.',
                1320288991
            );
        }

        return $cleanFileName;
    }

The code is based from the sanitizeFileName from the LocalDriver

Hope it can help

DerFrenk commented 1 year ago

Just releases a fix, thanks!