Problem/Motivation

It is not possible to upload files with an uppercase file extension (e.g. 'image.PNG') via media_directories_ui.

media_directories_ui checks the File Type via its extension. It does so case insensitive. Possible file extensions from Drupal Media (e.g. field.field.media.image.field_media_image. -> file_extensions) are always stored lowercase, it is not possible to add a uppercase variant to the allowed file extensions.

File upload in Media-Module (/media/add) compares case insensitive, uploading an uppercase-extension is possible. The behaviour of media_directories_ui deviates from media.

Steps to reproduce

1. Go to admin/content/browser, click 'Add Media'
2. Upload a file with an uppercase or mixedcase file extension, e.g. 'image.PNG'
3. The Upload-Modal returns the error Messsage

The specified file Firefox.PNG could not be uploaded.
- Only files with the following extensions are allowed: %files-allowed.

Proposed resolution

In media_directories/modules/media_directories_ui/src/MediaDirectoriesUiHelper.php, replace line 77

      if (in_array($extension, explode(' ', $field_config->getSetting('file_extensions')))) {

with either

      if (preg_match("/(^|\s)$extension(\s|$)/i", $field_config->getSetting('file_extensions'))===1) {

or (if you prefer a non-regex-approach)

      if (in_array(strtolower($extension), explode(' ', strtolower($field_config->getSetting('file_extensions'))))) {
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mullzk created an issue. See original summary.

mullzk’s picture

Issue summary: View changes
ytsurk’s picture

Status: Active » Needs work

Thx for your contribution.

I would prefer the non-regex approach and will commit that when I find time.

d.steindl made their first commit to this issue’s fork.

d.steindl’s picture

Version: 2.2.0-beta1 » 2.2.x-dev
Status: Needs work » Needs review

I've changed the case-insensitive check to use strtolower instead of a regex & created a merge request. Please review :)

mullzk’s picture

Thanks d.steindl. Your MR solves my problem
- Testing with 2.2.0-beta1 -> Upload of "testfile.PNG" fails with above error-message
- Testing with dev-3535402-fix-uppercase-file-extension -> Upload works as expected.
Moving to rtbc

mullzk’s picture

Status: Needs review » Reviewed & tested by the community

rang501 made their first commit to this issue’s fork.

rang501’s picture

Status: Reviewed & tested by the community » Fixed

Looks good to me, merged into 2.2.x

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.