[New-bugs-announce] [issue20392] Inconsistency with uppercase file extensions in MimeTypes.guess_type
report at bugs.python.org
Sat Jan 25 18:17:48 CET 2014
New submission from Rodrigo Parra:
The functions looks up for the file extension in three maps: types_map, suffix_map and encodings_map.
Lookup in types_map is case insensitive (by calling lower() first).
Lookup in both suffix_map and encodings_map is case sensitive.
These can lead to some seemingly counterintuitive results, like:
guess_type("foo.tar") == ("application/x-tar", None)
guess_type("foo.TAR") == ("application/x-tar", None)
guess_type("foo.tgz") == ("application/x-tar", "gzip")
guess_type("foo.TGZ") == (None, None)
guess_type("foo.tar.gz") == ("application/x-tar", "gzip")
guess_type("foo.TAR.GZ") == (None, None)
Lookup should be case insensitive at least for the suffix_map, in which case (b) would be solved. The submitted patch implements this change.
As for the encodings_map, I am not so sure, in particular because of the tar.Z extension. I found that the compress command expects the uppercase 'Z'. If someone is relying in the results of guess_type to call compress, errors could occur.
components: Library (Lib)
nosy: Rodrigo.Parra, tim.golden
title: Inconsistency with uppercase file extensions in MimeTypes.guess_type
versions: Python 3.4
Added file: http://bugs.python.org/file33703/case_guess_type.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce