Skip to content

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

Description

@shmulc8

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:

  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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions