parse_options_header accepts str | bytes | None, but passing a str
containing characters outside Latin-1 raises UnicodeEncodeError.
Reproduction
from python_multipart.multipart import parse_options_header
parse_options_header(
'form-data; name="upload"; filename="中文.doc"'
)
Observed on python-multipart 0.0.32 and current main
(d9cb4c62db5b9defeeaa99bfe0e4da51e760108f) with Python 3.14.6:
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1
This does not appear to affect ordinary HTTP multipart processing: raw header
bytes round-trip correctly, and Unicode filenames work through Starlette.
This is an API-contract/robustness question, not a security report.
Would you prefer to:
- Document that
str inputs must be Latin-1/WSGI-compatible;
- Validate this explicitly and raise a clearer error; or
- Support arbitrary Unicode
str values?
I would be happy to submit a focused PR with tests once the intended behavior
is clear.
parse_options_headeracceptsstr | bytes | None, but passing astrcontaining characters outside Latin-1 raises
UnicodeEncodeError.Reproduction
Observed on python-multipart 0.0.32 and current main
(
d9cb4c62db5b9defeeaa99bfe0e4da51e760108f) with Python 3.14.6:This does not appear to affect ordinary HTTP multipart processing: raw header
bytes round-trip correctly, and Unicode filenames work through Starlette.
This is an API-contract/robustness question, not a security report.
Would you prefer to:
strinputs must be Latin-1/WSGI-compatible;strvalues?I would be happy to submit a focused PR with tests once the intended behavior
is clear.