Skip to content

fix(tags): raise InvalidTag for malformed tag field counts#1238

Open
r266-tech wants to merge 1 commit into
pypa:mainfrom
r266-tech:fix-parse-tag-invalidtag-field-count
Open

fix(tags): raise InvalidTag for malformed tag field counts#1238
r266-tech wants to merge 1 commit into
pypa:mainfrom
r266-tech:fix-parse-tag-invalidtag-field-count

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

parse_tag() already raises InvalidTag for empty tag components, but malformed tags with too few or too many hyphen-separated fields still reached the tuple unpack and leaked ValueError.

This adds an explicit field-count check before unpacking so inputs such as py3-none and py3-none-any-extra follow the same public error contract.

Verification

  • uv run pytest tests/test_tags.py -q
  • uv run ruff check src/packaging/tags.py tests/test_tags.py
  • uv run ruff format --check src/packaging/tags.py tests/test_tags.py
  • Codex adversarial review: VERDICT: approve

Comment thread src/packaging/tags.py
Comment on lines 248 to 251

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EAFP over LBYL:

Suggested change
try:
interpreters, abis, platforms = component_parts
except ValueError as exc:
raise InvalidTag(f"Tag {tag!r} must have exactly three components") from exc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants