ExtensionMimeTypeGuesser breaks other mime_type_guesser services

Created on 3 July 2020, over 4 years ago
Updated 9 August 2024, 7 months ago

Problem/Motivation

The file.mime_type.guesser employs the service collector pattern to collection all services tagged as mime_type_guesser and the calls each of the guessers until one of them returns a guess. In doing so it accounts for the documented behavior of mime type guessers, as MimeTypeGuesserInterface::guess() documents the return value as:

string|null The mime type or NULL, if none could be guessed

However, the default (and only) mime type guesser in core (ExtensionMimeTypeGuesser) does not follow this behavior and itself returns a default mime type (application/octet-stream) if the extension of the file is not a known one. Thus, any mime type guesser that would otherwise come afterwards is ignored.

The concrete use case is to employ Symfony's FileBinaryMimeTypeGuesser to determine the file's mime type by introspecting the file itself. The service collector pattern suggests that this should be easily possible, but it is not.

Proposed resolution

No longer return a default value from ExtensionMimeTypeGuesser::guess(). Note that because this is a behavioral change, this is targeted for 9.1, even though it is a bug report. (This assessment was not coordinated with release managers and, thus, may be invalid in either direction.)

The default value could either be returned by the service collector itself, if none of the guessers returned anything, or we could add a FallbackMimeTypeGuesser that always returns the default and has a very low priority allowing others to intervene before the fallback, but after ExtensionMimeTypeGuesser.

๐Ÿ› Bug report
Status

Fixed

Version

10.4 โœจ

Component
File systemย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany tstoeckler Essen, Germany

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024