Projet

Général

Profil

Révision ecd39969

Ajouté par Assos Assos il y a environ 5 ans

Udpate to 7.65

Voir les différences:

drupal7/includes/file.inc
993 993
 * @return
994 994
 *   The destination filepath, or FALSE if the file already exists
995 995
 *   and FILE_EXISTS_ERROR is specified.
996
 *
997
 * @throws RuntimeException
998
 *   Thrown if the filename contains invalid UTF-8.
996 999
 */
997 1000
function file_destination($destination, $replace) {
1001
  $basename = drupal_basename($destination);
1002
  if (!drupal_validate_utf8($basename)) {
1003
    throw new RuntimeException(sprintf("Invalid filename '%s'", $basename));
1004
  }
998 1005
  if (file_exists($destination)) {
999 1006
    switch ($replace) {
1000 1007
      case FILE_EXISTS_REPLACE:
......
1002 1009
        break;
1003 1010

  
1004 1011
      case FILE_EXISTS_RENAME:
1005
        $basename = drupal_basename($destination);
1006 1012
        $directory = drupal_dirname($destination);
1007 1013
        $destination = file_create_filename($basename, $directory);
1008 1014
        break;
......
1218 1224
 * @return
1219 1225
 *   File path consisting of $directory and a unique filename based off
1220 1226
 *   of $basename.
1227
 *
1228
 * @throws RuntimeException
1229
 *   Thrown if the $basename is not valid UTF-8 or another error occurs
1230
 *   stripping control characters.
1221 1231
 */
1222 1232
function file_create_filename($basename, $directory) {
1233
  $original = $basename;
1223 1234
  // Strip control characters (ASCII value < 32). Though these are allowed in
1224 1235
  // some filesystems, not many applications handle them well.
1225 1236
  $basename = preg_replace('/[\x00-\x1F]/u', '_', $basename);
1237
  if (preg_last_error() !== PREG_NO_ERROR) {
1238
    throw new RuntimeException(sprintf("Invalid filename '%s'", $original));
1239
  }
1240

  
1226 1241
  if (substr(PHP_OS, 0, 3) == 'WIN') {
1227 1242
    // These characters are not allowed in Windows filenames
1228 1243
    $basename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $basename);
......
1563 1578
  if (substr($destination, -1) != '/') {
1564 1579
    $destination .= '/';
1565 1580
  }
1566
  $file->destination = file_destination($destination . $file->filename, $replace);
1581
  try {
1582
    $file->destination = file_destination($destination . $file->filename, $replace);
1583
  }
1584
  catch (RuntimeException $e) {
1585
    drupal_set_message(t('The file %source could not be uploaded because the name is invalid.', array('%source' => $form_field_name)), 'error');
1586
    return FALSE;
1587
  }
1567 1588
  // If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and
1568 1589
  // there's an existing file so we need to bail.
1569 1590
  if ($file->destination === FALSE) {
......
2130 2151
 *   'filename', and 'name' members corresponding to the matching files.
2131 2152
 */
2132 2153
function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
2154
  // Default nomask option.
2155
  $nomask = '/(\.\.?|CVS)$/';
2156

  
2157
  // Overrides the $nomask variable accordingly if $options['nomask'] is set.
2158
  //
2159
  // Allow directories specified in settings.php to be ignored. You can use this
2160
  // to not check for files in common special-purpose directories. For example,
2161
  // node_modules and bower_components. Ignoring irrelevant directories is a
2162
  // performance boost.
2163
  if (!isset($options['nomask'])) {
2164
    $ignore_directories = variable_get(
2165
      'file_scan_ignore_directories',
2166
      array()
2167
    );
2168

  
2169
    foreach ($ignore_directories as $index => $ignore_directory) {
2170
      $ignore_directories[$index] = preg_quote($ignore_directory, '/');
2171
    }
2172

  
2173
    if (!empty($ignore_directories)) {
2174
      $nomask = '/^(\.\.?)|CVS|' . implode('|', $ignore_directories) . '$/';
2175
    }
2176
  }
2177

  
2133 2178
  // Merge in defaults.
2134 2179
  $options += array(
2135
    'nomask' => '/(\.\.?|CVS)$/',
2180
    'nomask' => $nomask,
2136 2181
    'callback' => 0,
2137 2182
    'recurse' => TRUE,
2138 2183
    'key' => 'uri',

Formats disponibles : Unified diff