Skip to content

fix(metadata): accept UTF-8 charset case-insensitively - #1330

Merged
henryiii merged 2 commits into
pypa:mainfrom
r266-tech:r266-metadata-charset-casefold
Jul 20, 2026
Merged

henryiii merged 2 commits into
pypa:mainfrom
r266-tech:r266-metadata-charset-casefold

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Summary

  • accept Description-Content-Type charset values case-insensitively when they resolve to UTF-8
  • move lowercase/mixed-case UTF-8 examples into the valid validator cases
  • add a Metadata.from_email() regression for charset=utf-8

Tests

  • PYTHONPATH=src python3 -m pytest tests/test_metadata.py -q
  • python3 -m compileall -q src/packaging/metadata.py tests/test_metadata.py
  • git diff --check
  • uvx nox -s lint -- --show-diff-on-failure

@henryiii

Copy link
Copy Markdown
Contributor

According to https://www.w3.org/Protocols/rfc1341/7_1_Text.html, this should be case insensitive. I think the only question if it should be lower or casefold.

@r266-tech

Copy link
Copy Markdown
Contributor Author

lower() is sufficient here because charset names are ASCII tokens and the comparison target is the ASCII literal utf-8; casefold() would not accept any additional valid spelling. It also matches the nearby normalization style in metadata.py.

I've switched it to lower() in afa1c13. The focused metadata tests still pass (319 tests), along with Ruff check/format.

@henryiii

Copy link
Copy Markdown
Contributor

Ahh, should have looked back at the check, I was looking at the full set, but this is only utf-8. Yes, lower is sufficient.

@henryiii
henryiii merged commit abf0005 into pypa:main Jul 20, 2026
69 checks passed
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