diff -r 905d141e84da Lib/mimetypes.py --- a/Lib/mimetypes.py Sat Jan 25 15:32:06 2014 +0100 +++ b/Lib/mimetypes.py Sat Jan 25 13:47:37 2014 -0300 @@ -104,7 +104,7 @@ sensitive; type suffixes are first tried case sensitive, then case insensitive. - The suffixes .tgz, .taz and .tz (case sensitive!) are all + The suffixes .tgz, .taz and .tz are all mapped to '.tar.gz'. (This is table-driven too, using the dictionary suffix_map.) @@ -132,25 +132,22 @@ type = 'text/plain' return type, None # never compressed, so encoding is None base, ext = posixpath.splitext(url) - while ext in self.suffix_map: - base, ext = posixpath.splitext(base + self.suffix_map[ext]) + while ext.lower() in self.suffix_map: + base, ext = posixpath.splitext(base + self.suffix_map[ext.lower()]) if ext in self.encodings_map: encoding = self.encodings_map[ext] base, ext = posixpath.splitext(base) else: encoding = None + ext = ext.lower() types_map = self.types_map[True] if ext in types_map: return types_map[ext], encoding - elif ext.lower() in types_map: - return types_map[ext.lower()], encoding elif strict: return None, encoding types_map = self.types_map[False] if ext in types_map: return types_map[ext], encoding - elif ext.lower() in types_map: - return types_map[ext.lower()], encoding else: return None, encoding diff -r 905d141e84da Lib/test/test_mimetypes.py --- a/Lib/test/test_mimetypes.py Sat Jan 25 15:32:06 2014 +0100 +++ b/Lib/test/test_mimetypes.py Sat Jan 25 13:47:37 2014 -0300 @@ -77,6 +77,14 @@ strict=True) self.assertEqual(exts, ['.g3', '.g\xb3']) + def test_case_sensitivity(self): + eq = self.assertEqual + #all suffixes are case insensitive + eq(self.db.guess_type("foo.HTML"), self.db.guess_type("foo.html")) + eq(self.db.guess_type("foo.TGZ"), self.db.guess_type("foo.tgz")) + #encodings are case sensitive + eq(self.db.guess_type("foo.tar.Z"), ("application/x-tar", "compress")) + eq(self.db.guess_type("foo.tar.z"), (None, None)) @unittest.skipUnless(sys.platform.startswith("win"), "Windows only") class Win32MimeTypesTestCase(unittest.TestCase):