gh-92455: Respect case-sensitive mimetype suffixes#148782
Open
yuanx749 wants to merge 8 commits into
Open
Conversation
…sensitive-add-type
…sensitive-add-type
…sensitive-add-type
ifrh
reviewed
May 26, 2026
ifrh
left a comment
There was a problem hiding this comment.
I cannot approve the changes formaly, but they look good for me.
| eq(self.db.guess_type("scheme:foobar.tar.z"), (None, None)) | ||
|
|
||
| def test_added_types_case_sensitive_preferred(self): | ||
| self.db.add_type("text/x-r-script", ".R") |
Member
There was a problem hiding this comment.
"text/x-r-script" could be added to the database in future. It is better to use something less likely to be added.
Please add also tests for strict=False.
Contributor
Author
There was a problem hiding this comment.
Thanks for the review. I changed the test type and added tests for strict=False.
Member
|
#30229 changed also the code related to while True:
if ext in self.suffix_map:
base, ext = posixpath.splitext(base + self.suffix_map[ext])
continue
ext_lower = ext.lower():
if ext_lower in self.suffix_map:
base, ext = posixpath.splitext(base + self.suffix_map[ext_lower])
continue
break@kumaraditya303, what are your thoughts? |
…sensitive-add-type # Conflicts: # Lib/test/test_mimetypes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes gh-92455.
As described in the issue, the current implementation cannot find uppercase
extensions added via
mimetypes.add_type(). This appears to be a regression from gh-30229.This restores the lookup order documented for
mimetypes.guess_type():type suffixes are tried case-sensitively first, then case-insensitively.