python / cpython

The Python programming language
https://www.python.org
Other
63.51k stars 30.42k forks source link

mimetypes.guess_extension unable to get non-lowercase mimetype #83622

Open 7dbc2e6c-091a-47dc-b62e-98b63be23712 opened 4 years ago

7dbc2e6c-091a-47dc-b62e-98b63be23712 commented 4 years ago
BPO 39441
Nosy @inkhey, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-bug', '3.9'] title = 'mimetypes.guess_extension unable to get non-lowercase mimetype' updated_at = user = 'https://github.com/inkhey' ``` bugs.python.org fields: ```python activity = actor = 'iritkatriel' assignee = 'none' closed = False closed_date = None closer = None components = [] creation = creator = 'Inkhey' dependencies = [] files = [] hgrepos = [] issue_num = 39441 keywords = [] message_count = 2.0 messages = ['360601', '410653'] nosy_count = 2.0 nosy_names = ['Inkhey', 'iritkatriel'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue39441' versions = ['Python 3.9'] ```

7dbc2e6c-091a-47dc-b62e-98b63be23712 commented 4 years ago

mimetypes.guess_extension and mimetypes.guess_all_extensions doesn't work correctly with non-lowercase mimetype.

>>> import mimetypes
>>> mimetypes.guess_type('file.pptm')
('application/vnd.ms-powerpoint.presentation.macroEnabled.12', None)
>>> mimetypes.guess_extension("application/vnd.ms powerpoint.presentation.macroEnabled.12")

>>

This issue exist because we automatically convert type as lower in guess_all_extensions, but we do not prevent added type to be lowercase.

iritkatriel commented 2 years ago

See also bpo-20392.