8000 gh-75223: Reject undotted extensions in mimetypes.add_type by OddBloke · Pull Request #2895 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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.

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Assert output first, expected result second; link to method in news
  • Loading branch information
hugovk authored Nov 16, 2024
commit ef5cf14e235c00e67e6f7bf43e62a4f3dbe7d713
8 changes: 4 additions & 4 deletions Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ def test_keywords_args_api(self):

def test_added_types_are_used(self):
mime_type, _ = mimetypes.guess_type('test.myext')
self.assertEqual(None, mime_type)
self.assertEqual(mime_type, None)
mimetypes.add_type('testing/type', '.myext')
mime_type, _ = mimetypes.guess_type('test.myext')
self.assertEqual('testing/type', mime_type)
self.assertEqual(mime_type, 'testing/type')

def test_add_type_with_undotted_extension_raises_exception(self):
with self.assertRaises(ValueError):
Expand All @@ -320,9 +320,9 @@ def test_add_type_with_undotted_extension_raises_exception(self):
def test_add_type_with_empty_extension_emits_warning(self):
with warnings.catch_warnings(record=True) as wlog:
mimetypes.add_type('testing/type', '')
self.assertEqual(1, len(wlog))
self.assertEqual(len(wlog), 1)
warning = wlog[0]
self.assertEqual('Empty extension specified', str(warning.message))
self.assertEqual(str(warning.message), 'Empty extension specified')


@unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Reject undotted extensions in mimetypes.add_type.
Reject undotted extensions in :meth:`MimeTypes.add_type`.
Loading
0