Kludex / Kludex/python-multipart

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

Aperta
#319 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
532
Fork
93
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

`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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.