summaryrefslogtreecommitdiffstats
path: root/Lib/mimetypes.py
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-03-15 13:25:43 (GMT)
committerGitHub <noreply@github.com>2022-03-15 13:25:43 (GMT)
commit5dd7ec52b83e7f239774cf7478106fcc7b0a36f3 (patch)
treed2e63b16267705390960ba93c896a51d416f0c98 /Lib/mimetypes.py
parent22403d3a814ae2fd7e531479396959d639b98559 (diff)
downloadcpython-5dd7ec52b83e7f239774cf7478106fcc7b0a36f3.zip
cpython-5dd7ec52b83e7f239774cf7478106fcc7b0a36f3.tar.gz
cpython-5dd7ec52b83e7f239774cf7478106fcc7b0a36f3.tar.bz2
bpo-20392: Fix inconsistency with uppercase file extensions in mimetypes.guess_type (GH-30229)
Diffstat (limited to 'Lib/mimetypes.py')
-rw-r--r--Lib/mimetypes.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 4750408..1aa3246 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -141,25 +141,23 @@ class MimeTypes:
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 := ext.lower()) in self.suffix_map:
+ base, ext = posixpath.splitext(base + self.suffix_map[ext_lower])
+ # encodings_map is case sensitive
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