mime_guess icon indicating copy to clipboard operation
mime_guess copied to clipboard

The suggested extension for image/jpeg should probably be "jpeg" or "jpg", not "jpe"

Open mortie opened this issue 5 years ago • 3 comments
trafficstars

I think the first result from mime_guess::get_mime_extensions should be one of the most common extensions used for a given mime type. Currently, it returns "jpe" for image/jpeg, even though "jpg" and "jpeg" seem to be significantly more common.

mortie avatar May 25 '20 22:05 mortie

This isn't trivial. Reverse mappings are returned in lexicographical order because the source list is sorted in lexicographical order. To give the reverse mapping the correct priority we'd either have to break the sort order of the source list (which would make it a pain to maintain), or we have to assign a key for reverse-mapping priority for each entry. I think the latter is probably the best.

abonander avatar Aug 25 '20 08:08 abonander

Thinking about this more, I want to redo the organization of mime types in the source so it essentially pairs a list of extensions and a list of MIME types with the "most relevant extension" and "most relevant MIME type" sorted first. The list as a whole should be sorted lexicographically just for sanity reasons.

I also think there's a lot of syntactic overhead in the list right now as it's defined in a Rust source file, so instead I think I want to devise a really simple text format for the list. I'm thinking something like this:

; comment
ext ext ext... : mime mime mime...

jpeg jpg jpe : application/jpeg

abonander avatar Aug 03 '21 01:08 abonander

Gonna +1 this. get_mime_extensions is fairly useless for getting an appropriate extension from a mime type - for example, text/plain has several dozen extensions associated, and the first one is "asm".

You might want to check out the mime2ext crate, which allegedly has a better mapping, and the description mentions this crate and this deficiency.

ColonelThirtyTwo avatar Apr 26 '22 16:04 ColonelThirtyTwo