From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 14 Feb 2025 17:45:28 +0000 (+0100) Subject: gh-128703: Fix mimetypes.guess_type for empty Content-Type in registry (GH-128854) X-Git-Tag: v3.12.10~216 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a122415c022b681b28fb348f34a9882f1d9fec33;p=thirdparty%2FPython%2Fcpython.git gh-128703: Fix mimetypes.guess_type for empty Content-Type in registry (GH-128854) (cherry picked from commit 303043f5062c1e7ffb7907abde61dbf13c98f8e9) Co-authored-by: RUANG (James Roy) --- diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 10f3ddc5a152..64b550b06901 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -95,6 +95,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 000000000000..1e6af90bc04b --- /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.