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'
I’m trying to define a custom MIME type for a file extension that contains a dot (
.), butdetectMimeTypeonly seems to recognize single-segment extensionsIn this case, a simple extension like
.towworks as expected and multi-segment extension like.be.pit&.fr.pitare not detectedLooking at the implementation of
detectMimeType, it appears that only the substring after the last dot in the filename (in this casepit) 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.pitis registered viadefineMimeType, I would expectdetectMimeType('filename.be.pit')to return'application/x-be-pit-document'