diff -u b/core/modules/file/file.post_update.php b/core/modules/file/file.post_update.php --- b/core/modules/file/file.post_update.php +++ b/core/modules/file/file.post_update.php @@ -10,8 +10,7 @@ use Drupal\file\Plugin\Field\FieldType\FileItem; /** - * Adds txt to allowed extensions for all fields that allow uploads of insecure - * files. + * Add txt to allowed extensions for all fields that allow uploads of insecure files. */ function file_post_update_update_allowed_file_extensions_if_insecure(&$sandbox = NULL) { if (\Drupal::config('system.file')->get('allow_insecure_uploads')) { @@ -30,7 +29,7 @@ foreach ($allowed_extensions as $extension) { if (preg_match(FILE_INSECURE_EXTENSION_REGEX, 'test.' . $extension)) { // Add the txt extension to the list of allowed extensions if an - // insecure (one|extension) is allowed. + // insecure extension is allowed. $allowed_extensions_string .= ' txt'; $field->setSetting('file_extensions', $allowed_extensions_string); return TRUE; diff -u b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php --- b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php @@ -236,17 +236,11 @@ // If insecure uploads are not allowed then error if txt is not an allowed // extension. - if (!in_array('txt', $extension_array, TRUE) && !\Drupal::config('system.file')->get('allow_insecure_uploads')) { - $unique_extensions = []; - // Filter out definitions that are not intended to be placed by the UI. - $unique_extensions = array_filter($extension_array, function (string $extension) { - if (!in_array($extension, $unique_extensions) && preg_match(FILE_INSECURE_EXTENSION_REGEX, 'test.' . $extension)) { - return $extension; + if (!in_array('txt', $extension_array) && !\Drupal::config('system.file')->get('allow_insecure_uploads')) { + foreach ($extension_array as $extension) { + if (preg_match(FILE_INSECURE_EXTENSION_REGEX, 'test.' . $extension)) { + $form_state->setError($element, t('Add %txt_extension to the list of allowed extensions to securely upload files with a %extension extension. The %txt_extension extension will then be added automatically.', ['%extension' => $extension, '%txt_extension' => 'txt'])); } - }); - if (!empty($unique_extensions)) { - $unique_extensions = implode(' or ', $unique_extensions); - $form_state->setError($element, t('Add %txt_extension to the list of allowed extensions to securely upload files with a %extension extension. The %txt_extension extension will then be added automatically.', ['%extension' => $unique_extensions, '%txt_extension' => 'txt'])); } } }