Skip to content

[mime] detectMimeType doesn't recognize multi-part file extensions #11099

@MichaelDeBoey

Description

@MichaelDeBoey

I’m trying to define a custom MIME type for a file extension that contains a dot (.), but detectMimeType only seems to recognize single-segment extensions

defineMimeType({
  extensions: ['tow'],
  mimeType: 'application/x-tow-document',
});
defineMimeType({
  extensions: ['be.pit'],
  mimeType: 'application/x-be-pit-document',
});
defineMimeType({
  extensions: ['fr.pit'],
  mimeType: 'application/x-fr-pit-document',
});

detectMimeType('filename.tow') // application/x-tow-document
detectMimeType('filename.be.pit') // undefined
detectMimeType('filename.fr.pit') // undefined

In this case, a simple extension like .tow works as expected and multi-segment extension like .be.pit & .fr.pit are not detected

Looking at the implementation of detectMimeType, it appears that only the substring after the last dot in the filename (in this case pit) is considered, instead of matching against the full registered extension (be.pit/fr.pit)

Some domain-specific formats rely on multi-part extensions.
When only the last segment is evaluated, it's impossible to distinguish between related formats that share the same final segment.

So if an extension like be.pit is registered via defineMimeType, I would expect detectMimeType('filename.be.pit') to return 'application/x-be-pit-document'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions