summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRUANG (James Roy) <longjinyii@outlook.com>2025-02-14 17:26:26 (GMT)
committerGitHub <noreply@github.com>2025-02-14 17:26:26 (GMT)
commit303043f5062c1e7ffb7907abde61dbf13c98f8e9 (patch)
tree603d91aa78959ab18838171990806b598dc8a356
parent3402e133ef26736296c07992266a82b181a5d532 (diff)
downloadcpython-303043f5062c1e7ffb7907abde61dbf13c98f8e9.zip
cpython-303043f5062c1e7ffb7907abde61dbf13c98f8e9.tar.gz
cpython-303043f5062c1e7ffb7907abde61dbf13c98f8e9.tar.bz2
gh-128703: Fix mimetypes.guess_type for empty Content-Type in registry (GH-128854)
-rw-r--r--Lib/mimetypes.py2
-rw-r--r--Misc/NEWS.d/next/Library/2025-01-15-12-04-30.gh-issue-128703.6WPf38.rst2
2 files changed, 4 insertions, 0 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 7532383..3e1c3cf 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -90,6 +90,8 @@ class MimeTypes:
list of standard types, else to the list of non-standard
types.
"""
+ if not type:
+ return
self.types_map[strict][ext] = type
exts = self.types_map_inv[strict].setdefault(type, [])
if ext not in exts:
diff --git a/Misc/NEWS.d/next/Library/2025-01-15-12-04-30.gh-issue-128703.6WPf38.rst b/Misc/NEWS.d/next/Library/2025-01-15-12-04-30.gh-issue-128703.6WPf38.rst
new file mode 100644
index 0000000..1e6af90
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-15-12-04-30.gh-issue-128703.6WPf38.rst
@@ -0,0 +1,2 @@
+Fix :func:`mimetypes.guess_type` to use default mapping for empty
+``Content-Type`` in registry.