Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
All binary file responses (initial reports was config export) if neither the fileinfo extension is installed nor the file binary is callable. This is due to BinaryFileResponse in HTTP foundation calling the Symfony MIME type guesser in the prepare method.
Proposed resolution
Call Symfony\Component\HttpFoundation\File\MimeType::getInstance()->register($this->container->get('file.mime_type.guesser'))
early, in DrupalKernel::preHandle()
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Novice | Instructions | |
Add automated tests | Instructions | ||
Add steps to reproduce the issue | Instructions |
User interface changes
No.
API changes
No.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2387443.13.patch | 3.92 KB | alexpott |
#13 | 11-13-interdiff.txt | 4.65 KB | alexpott |
#12 | interdiff.txt | 4.53 KB | dawehner |
#11 | 2387443.11.patch | 4.1 KB | alexpott |
Comments
Comment #1
chx CreditAttribution: chx commentedComment #2
dawehnerLet's disagree with the solution.
Comment #3
chx CreditAttribution: chx commentedI totally agree with that.
Comment #4
chx CreditAttribution: chx commentedBut we have the container, so.
Comment #5
webchickLet's get a bit more confident about the solution. ;)
Also if it's literally a matter of adding one line to a method somewhere, let's call this a Novice task and see what happens. :)
Comment #6
YesCT CreditAttribution: YesCT commentedadding the tasks information, so people can see what needs to be done, and instructions on how to do it, which is important for helping people get involved. The dreditor insert tasks button is useful for this.
I think we need some steps to reproduce also. adding needs issue summary update for that.
was this discovered while working on another issue?
--
Can we add tests for this?
I'm going to guess yes.
If not, please update the issue summary to say why not.
Comment #7
mikeryanComment #8
dawehnerComment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedi poked at this, but it's hard to see how to build a test for it given it will only fail for non-code-related issues.
we'd need a specially built php which disabled fileinfo, which sounds like a bunch of work for the testbot admins.
Comment #10
andypostWhy not just throw sane exception if fileinfo is unavailable for an export exactly?
PS: Suppose each component/service can depends on php internals but how to properly expose this deps...
Comment #11
alexpottAll other binary responses will fail. So that's anything downloaded through the FileDownloadController::download method (eg private files), first time image style derivatives and locale gettext downloads.
Also we could need this if we use Symfony's file or image validators.
@andypost this issue is not about only the fileinfo extension...
From \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser - if this code does not register a guesser we have problems.
Comment #12
dawehnerIs there a reason why we don't pass along the container? We should have it available here
Let's describe it a bit better, we register an additional one.
Afaik we have the container available and so can just pass it along
I would vote for renaming the test file, to make life easier.
Learn about $this->readAttribute , luke :)
Comment #13
alexpottre #12 all sounds sensible. Move the test to Drupal\Tests\Core\File as well.
Comment #14
dawehnerAlright, thank you!
I think this is kinda pointless, given that this would be incredible hard to setup. (find a bad hoster ...)
Comment #15
chx CreditAttribution: chx commentedSee my #2290261-52: Revert php_fileinfo requirement writeup on why / how it'd be better to run Symfony's guessers if they are available and only run Drupal's if they aren't.
Comment #16
alexpott@chx I think we could attempt that in a separate issue. We registering
Drupal\Core\File\MimeType\MimeTypeGuesser
which can have additional mime type guessers added during a compiler pass. Created #2388749: Register symfony's mime guessers if they are supported to do this.Comment #17
catchThanks for opening the follow-up. That looks worth looking at, but happy with this for the straightforward fix.
Committed/pushed to 8.0.x, thanks!