Changeset 488


Ignore:
Timestamp:
Aug 26, 2014 11:50:45 AM (10 years ago)
Author:
anonymous
Message:

Improved cleanFileName method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Upload.inc.php

    r485 r488  
    474474
    475475    /**
    476      * Removes unsafe characters from file name.
     476     * Removes non-latin characters from file name, using htmlentities to convert known weirdos into regular squares.
    477477     *
    478478     * @access  public
     
    482482    public function cleanFileName($file_name)
    483483    {
    484         $bad  = 'áéíóúàÚìòùÀëïöÌÁÉÍÓÚÀÈÌÒÙÄËÏÖÜâêîÎûÂÊÎÔÛñçÇ';
    485         $good = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncC';
    486         $file_name = trim($file_name);
    487         $file_name = strtr($file_name, $bad, $good);
    488         $file_name = preg_replace('/[^-\w.,~_=+()@]+/i', '_', $file_name);
    489         $file_name = mb_substr($file_name, 0, 250);
    490         return $file_name;
     484        $file_name = preg_replace(array(
     485            '/&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/ui',
     486            '/&(?:amp);/ui',
     487            '/[&;]+/u',
     488            '/[^a-zA-Z0-9()@._=+-]+/u',
     489            '/^_+|_+$/u'
     490        ), array(
     491            '$1',
     492            'and',
     493            '',
     494            '_',
     495            ''
     496        ), htmlentities($file_name, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'));
     497        return mb_substr($file_name, 0, 250);
    491498    }
    492499
Note: See TracChangeset for help on using the changeset viewer.