gh-75223: Reject undotted extensions in mimetypes.add_type by OddBloke · Pull Request #2895 · python/cpython (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
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
[ Show hidden characters]({{ revealButtonHref }})
I've opened this now to get feedback on whether this is an appropriate change to make. Does it need a warning first, before it becomes the default behaviour?
(At a minimum, I would expect to need to add to documentation.)
As said in https://bugs.python.org/issue31040, please use startswith
instead of find.
There is one case where it works without a dot:
>>> mimetypes.add_type('empty', '')
>>> mimetypes.guess_type('')
('empty', None)
And someone may have used it to distinguish between emptyness and type not found. What I propose:
Emit a warning in case the ext is empty, else ValueError in case the type does not start with a dot, to ensure we're not breaking any code.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.
Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again
. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.
Extensions that don't start with a dot will never be found by methods/functions that act on the registry, so we should stop users from mistakenly adding them.
The one exception is the empty string extension. This could be in use to detect absent extensions, so instead of raising a ValueError we emit a warning.
I have made the requested changes; please review again.
Thanks for making the requested changes!
@JulienPalard: please review the changes made to this pull request.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.
Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again
. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.
And if you don't make the requested changes, you will be put in the comfy chair!
This comment was marked as outdated.
This comment was marked as outdated.
arhadthedev changed the title
bpo-31040: Reject undotted extensions in mimetypes.add_type gh-75223: Reject undotted extensions in mimetypes.add_type
hugovk previously requested changes Nov 6, 2024
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits, but also the tests need updating to match the implementation change in f0c1bf7 (#2895).
This comment was marked as resolved.
This comment was marked as resolved.
hugovk dismissed their stale review
Dismissing my review, I've updated the PR
OddBloke mannequin mentioned this pull request
This PR is stale because it has been open for 30 days with no activity.
IMO, this is a backwards-incompatible change and should be deprecated with a warning, and documented. (For example, if add_type
is fed from a data file, this PR can change a relatively harmless data-entry error into a hard failure. Or someone could use types_map
directly.)
hugovk marked this pull request as draft
Thanks, please see #128638 to deprecate it first, and I've marked this as a draft until it's ready for merge.
This PR is stale because it has been open for 30 days with no activity.