Kludex / Kludex/python-multipart

Clarify or handle non-Latin-1 str input in parse_options_header

Open
#319 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
532
Forks
93
PR merge metrics
No merged PRs in 30d

Description

`parse_options_header` accepts `str | bytes | None`, but passing a `str`
containing characters outside Latin-1 raises `UnicodeEncodeError`.

### Reproduction

```python
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:

```text
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:

1. Document that `str` inputs must be Latin-1/WSGI-compatible;
2. Validate this explicitly and raise a clearer error; or
3. Support arbitrary Unicode `str` values?

I would be happy to submit a focused PR with tests once the intended behavior
is clear.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with parse_options_header in the python_multipart.multipart module and reproduce the UnicodeEncodeError using the example in the issue. Read the surrounding tests and determine whether the intended behavior is documentation, explicit validation, or Unicode support. Done means the chosen contract is implemented and covered by focused tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.