fix: tighten MIME type validation regex (#35)#60
Conversation
Type and subtype must now start with a letter. Rejects values like 123/456 and _/_ that previously passed. Parameter syntax now requires name=value format. Closes #35 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
cmeans
left a comment
There was a problem hiding this comment.
QA Review — PR #60
Verdict: Zero findings. Ready for maintainer signoff.
Checkboxes verified
CHECKBOX 1: test_read_raw_rejects_numeric_mime → PASSED (123/456 rejected)
CHECKBOX 2: test_read_raw_rejects_underscore_mime → PASSED (_/_ rejected)
CHECKBOX 3: test_read_raw_accepts_custom_mime → PASSED (application/x-custom accepted)
CHECKBOX 4: pytest -q → 453 passed, 6 deselected, 8 xfailed
All checkboxes ticked.
Code review
Old regex: r"^[\w.+\-]+/[\w.+\-]+(;[\w.+\-=]+)*$" — accepted 123/456, _/_, ;garbage
New regex: r"^[a-zA-Z][\w.+\-]*/[a-zA-Z][\w.+\-]*(;\s*[\w.+\-]+=[\w.+\-]+)*$" — type/subtype must start with a letter, parameters must be name=value
Per RFC 2045 §5.1, type and subtype tokens must start with a letter. The new regex is more RFC-compliant. \s* after ; allows ; charset=utf-8 (common in the wild). Custom types like application/x-custom still pass. ✓
Other checks
- CHANGELOG:
### Fixedin[Unreleased]. Accurate.Closes #35. ✓ - CI: All green. ✓
- Diff scope: 3 files, +30/-2, single commit. Clean. ✓
Findings
None.
|
Applying |
Summary
123/456,_/_)name=value(rejects;garbage)application/x-customstill acceptedTest plan
uv run pytest tests/test_server.py::test_read_raw_rejects_numeric_mime -vpassesuv run pytest tests/test_server.py::test_read_raw_rejects_underscore_mime -vpassesuv run pytest tests/test_server.py::test_read_raw_accepts_custom_mime -vpassesuv run pytest -q-- 453 passed, 6 deselected, 8 xfailedCloses #35