Skip to content

Parse MIME subtypes containing dots and plus signs in full - #22

Open
webpatser wants to merge 1 commit into
amphp:2.xfrom
webpatser:fix/mime-subtypes
Open

webpatser wants to merge 1 commit into
amphp:2.xfrom
webpatser:fix/mime-subtypes

Conversation

@webpatser

Copy link
Copy Markdown

DocumentRoot::loadMimeFileTypes() truncates any subtype that contains a dot or a plus sign after the first segment. The regex only allows [a-z0-9\-]+ with one optional +suffix, so with the bundled resources/mime:

Extension Expected Served today
xls application/vnd.ms-excel application/vnd
docx application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vnd

Every vnd.* type in the bundled file ends up as application/vnd, which makes browsers fall back to generic handling for those downloads.

This came out of the fixes I made in my fork (webpatser/fledge-fiber), sending them back upstream as asked. Hope it catches a clean wave.

Summary

  • Subtype pattern is now [a-z0-9][a-z0-9.+\-]*, so dotted, plus and dash subtypes are kept whole.
  • No change to the mime file itself.

Test plan

  • testBundledMimeFileIsParsedInFull: every line of the bundled mime file maps to exactly its listed type (last entry wins for duplicate extensions, matching the parser).
  • testDottedPlusAndDashSubtypesAreNotTruncated: xls, svg and docx resolve to their full types.
  • Both tests fail on 2.x without the fix and pass with it; full suite green.

@webpatser

Copy link
Copy Markdown
Author

Heads up on the red CI: the jobs fail at "Set up job" because the workflow still uses actions/cache@v2, which GitHub now refuses to run. The 2.x branch fails the same way, so it's unrelated to this change. Locally the full suite is green (2051 tests), and the two new tests fail without the fix.

Happy to send a separate PR bumping the cache action to v4 if that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant