File uploads broken since D10.2

Created on 16 October 2024, about 2 months ago

Problem/Motivation

Attempting to upload a file using Drupal 10.2.2 or later throws an error:

TypeError: Drupal\file\Upload\FileUploadHandler::handleExtensionValidation(): Return value must be of type string, null returned in Drupal\file\Upload\FileUploadHandler->handleExtensionValidation() (line 431 of /web/core/modules/file/src/Upload/FileUploadHandler.php).

This appears to have changed in this commit:
📌 Move file upload validation from file.module to constraint validators Fixed

The regression was noticed here:
🐛 file_save_upload broken by 10.2.x Needs work

NB: This behaviour may change again in the future: : 📌 Simplify how 'allow all extensions' file upload validation works Active

Steps to reproduce

  1. Install Site Verify 2.0.0-alpha2 on Drupal 10.3.6
  2. Attempt to upload a Google verification file

Proposed resolution

On the 2.0.x branch only, change the validators used when calling file_save_upload:

      // Import the uploaded verification file.
-     $validators = ['file_validate_extensions' => []];
+     $validators = ['file_validate_extensions' => ''];
      if ($file = file_save_upload('file_upload', $validators, FALSE, 0, FileSystemInterface::EXISTS_REPLACE)) {

This has been fixed in 📌 Automated Drupal 11 compatibility fixes for site_verify RTBC by using the FileExtension constraint validator for versions D10.2.2 and above.

Remaining tasks

  • ✅ File an issue
  • ➖ Addition/Change/Update/Fix
  • ➖ Code review by maintainers
  • ➖ Credit contributors
  • ➖ Release notes snippet
  • ❌ Release

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

  • Use correct parameter for file_validate_extensions validator.
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇦🇺Australia elc

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024