GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-75223: Reject undotted extensions in `mimetypes.add_type()` by OddBloke · Pull Request #2895 · python/cpython

gh-75223: Reject undotted extensions in mimetypes.add_type() #2895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OddBloke wants to merge 16 commits into python:main from OddBloke:fix-for-31040

Uh oh!

There was an error while loading. Please reload this page.

Closed

gh-75223: Reject undotted extensions in mimetypes.add_type() #2895

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2e6a0e5
Add a test for mimetypes.add_type
OddBloke Jul 26, 2017
1485be9
bpo-31040: Reject undotted extensions in mimetypes.add_type
OddBloke Jul 26, 2017
f0c1bf7
Address the review
arhadthedev Apr 15, 2023
0d9bec2
Merge branch 'main' into fix-for-31040
arhadthedev Apr 15, 2023
2f23267
Merge branch 'main' into fix-for-31040
hugovk Nov 6, 2024
ef5cf14
Assert output first, expected result second; link to method in news
hugovk Nov 16, 2024
bac8d5d
Assert adding MIME type with empty extension emits no warning
hugovk Nov 16, 2024
e177398
Assert exception message when adding MIME type with undotted extension
hugovk Nov 16, 2024
094f69b
Remove unused import
hugovk Nov 16, 2024
cbc5421
Fix Sphinx reference; replace bpo with gh-issue
hugovk Nov 16, 2024
41d4e89
Replace with more useful test case
hugovk Nov 16, 2024
50179cf
Improve wording: avoid triple negative
hugovk Nov 16, 2024
352811b
Fix news filename
hugovk Nov 16, 2024
b34278f
Merge branch 'main' into fix-for-31040
StanFromIreland May 9, 2026
c1b6fec
Remove duplicate after merge, add to What's New and tidy up
StanFromIreland May 9, 2026
c491311
!fixup leftover line
StanFromIreland May 9, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

4 changes: 0 additions & 4 deletions 4 Doc/library/mimetypes.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ than one MIME-type database; it provides an interface similar to the one of the
When *strict* is ``True`` (the default), the mapping will be added to the
official MIME types, otherwise to the non-standard ones.

.. deprecated-removed:: 3.14 3.16
Invalid, undotted extensions will raise a
:exc:`ValueError` in Python 3.16.


.. _mimetypes-cli:

Expand Down
7 changes: 7 additions & 0 deletions 7 Doc/whatsnew/3.16.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ functools
* Calling the Python implementation of :func:`functools.reduce` with *function*
or *sequence* as keyword arguments has been deprecated since Python 3.14.

mimetypes
---------

* Passing an invalid *ext* (that is, an extension that is not empty and does not
start with a '.') to :meth:`mimetypes.MimeTypes.add_type` now raises a :exc:`ValueError`.
(Contributed by Daniel Watkins, Hugo van Kemenade, and Stan Ulbrych in :gh:`75223`.)

symtable
--------

Expand Down
9 changes: 1 addition & 8 deletions 9 Lib/mimetypes.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@ def add_type(self, type, ext, strict=True):
Valid extensions are empty or start with a '.'.
"""
if ext and not ext.startswith('.'):
from warnings import _deprecated

_deprecated(
"Undotted extensions",
"Using undotted extensions is deprecated and "
"will raise a ValueError in Python {remove}",
remove=(3, 16),
)
raise ValueError("Extensions should start with a '.' or be empty")

if not type:
return
Expand Down
8 changes: 5 additions & 3 deletions 8 Lib/test/test_mimetypes.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ def test_added_types_are_used(self):
mime_type, _ = mimetypes.guess_type('test.myext')
self.assertEqual(mime_type, 'testing/type')

def test_add_type_with_undotted_extension_deprecated(self):
with self.assertWarns(DeprecationWarning):
mimetypes.add_type("testing/type", "undotted")
def test_add_type_with_undotted_extension_raises_exception(self):
Comment thread
hugovk marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

with self.assertRaisesRegex(
ValueError, "Extensions should start with a '.' or be empty"
):
mimetypes.add_type('testing/type', 'undotted')


@unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2019-09-10-09-28-52.gh-issue-75223.VyAJS9.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reject undotted extensions in :meth:`mimetypes.MimeTypes.add_type`.
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.