Skip to content
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

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

OddBloke
Copy link

@OddBloke OddBloke commented Jul 26, 2017

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.

https://bugs.python.org/issue31040

@OddBloke
Copy link
Author

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.)

@JulienPalard
Copy link
Member

JulienPalard commented Sep 10, 2019

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.

Lib/mimetypes.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

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.

@OddBloke OddBloke requested a review from a team as a code owner September 10, 2019 12:45
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.
@OddBloke
Copy link
Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@JulienPalard: please review the changes made to this pull request.

Lib/mimetypes.py Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

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!

@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Feb 20, 2022
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jul 29, 2022
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Aug 30, 2022
@arhadthedev arhadthedev changed the title bpo-31040: Reject undotted extensions in mimetypes.add_type gh-75223: Reject undotted extensions in mimetypes.add_type Apr 15, 2023
@arhadthedev arhadthedev added topic-email stdlib Python modules in the Lib dir labels Apr 15, 2023
@arhadthedev arhadthedev removed the stale Stale PR or inactive for long period of time. label Apr 15, 2023
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label May 16, 2023
@hugovk hugovk dismissed JulienPalard’s stale review November 6, 2024 16:43

Review was addressed

hugovk
hugovk previously requested changes Nov 6, 2024
Copy link
Member

@hugovk hugovk left a comment

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).

Lib/test/test_mimetypes.py Outdated Show resolved Hide resolved
Lib/test/test_mimetypes.py Outdated Show resolved Hide resolved
Lib/test/test_mimetypes.py Outdated Show resolved Hide resolved
Lib/test/test_mimetypes.py Show resolved Hide resolved
@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Nov 6, 2024
@bedevere-app

This comment was marked as resolved.

@bedevere-app

This comment was marked as resolved.

@hugovk hugovk requested review from hugovk and removed request for hugovk November 16, 2024 13:13
@hugovk hugovk dismissed their stale review November 16, 2024 13:15

Dismissing my review, I've updated the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes stdlib Python modules in the Lib dir topic-email
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants