Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mortie opened this issue May 25, 2020 · 3 comments

Comments

@mortie
Copy link

mortie commented May 25, 2020

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.

@abonander
Copy link
Owner

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
Copy link
Owner

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

@ColonelThirtyTwo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants