fix(utils): reject empty project name in parse_wheel_filename/parse_sdist_filename#1305
Merged
brettcannon merged 1 commit intoJun 29, 2026
Conversation
parse_wheel_filename and parse_sdist_filename silently accepted a
filename whose distribution name was empty (e.g. '-1.0-py3-none-any.whl'
or '-1.0.tar.gz') and returned ('', Version(...)) instead of raising the
documented InvalidWheelFilename / InvalidSdistFilename.
An empty name is invalid per the binary/source distribution-format specs
and is already rejected by canonicalize_name(validate=True). Make the
parsers fail fast:
- wheel: _wheel_name_regex used '*' (zero-or-more) so it matched the
empty string; switch to '+' so the existing 'Invalid project name'
branch fires.
- sdist: add an explicit empty-name guard after the rpartition, before
canonicalize_name.
Extends the existing empty-component parametrize lists with regression
cases. Sibling of the empty-tag-component rejection in pypa#1234.
brettcannon
approved these changes
Jun 29, 2026
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.
parse_wheel_filenameandparse_sdist_filenamesilently accept a filename whose distribution name is empty and return("", Version(...))instead of raising the documentedInvalidWheelFilename/InvalidSdistFilename:An empty name is invalid per the binary/source distribution-format specs, and
canonicalize_name(..., validate=True)already rejects it — so the parsers are inconsistent with their own:raises:contract, and callers using them to validate artifact filenames get a silently-empty name instead of a clear parse error.Fix
_wheel_name_regexused*(zero-or-more), so it matched the empty string and the existing "Invalid project name" branch never fired; change it to+.rpartition, beforecanonicalize_name.Both raise the parser-specific exception (
InvalidWheelFilename/InvalidSdistFilename, bothValueErrorsubclasses) so back-compat holds; valid filenames are unaffected. Regression cases added to the existing empty-component parametrize lists.Sibling of the empty-tag-component rejection in #1234.