Problem/Motivation
If a file extension is made up of several parts, concatenated by a dot, and the rightmost part has a MIME type mapped, ExtensionMimeTypeGuesser::guessMimeType() returns the MIME type of the rightmost part and not the more accurate MIME type of the full extension.
Steps to reproduce
1) Alter the MIME type map to have the 'z' extension map to the application/x-compress MIME type
2) Guess a file named 'foo.pcf.z'. You would expect the MIME type returned to be application/x-font, because 'pcf.z' extension maps to that MIME type. application/x-compress is returned instead, because 'z' extension maps to application/x-compress now, and the rightmost part is attempted first.
Proposed resolution
Change the logic to test from attempting extensions from the full one and looping by removing the leftmost part until a match is found.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3477346-fix-mime-type-guesser-condition.patch | 851 bytes | et.cetera |
Issue fork drupal-3477346
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
Comment #3
mondrakeComment #4
mondrakeComment #5
smustgrave commentedRan test-only feature
Issue summary appears complete and change makes sense to me
Don't see anything else holding it up.
Comment #6
larowlanOne minor comment about a slight loss of coverage. Fine to self RTBC
Comment #7
mondrakeSelf-RTBC as granted in #6.
Comment #8
larowlanCommitted a5b0f9c and pushed to 11.x. Thanks!
As this is a bug and there is little risk of disruption, backported to 11.0.x, 10.4.x and 10.3.x
Thanks!
Comment #15
et.cetera commentedThis change introduced an issue if you have filenames which are equal to 0 (i.e. 0.jpg), because the while condition does not apply:
I appended a patch for core version 10.3.10 to adjust this condition and fix the issue in my case.
Comment #16
kim.pepper@et.cetera see #3487488: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) in the extension parts like foo.0.zip for that bug fix.