Skip to content

Accept Unicode str values in parse_options_header - #321

Open
gyanu2507 wants to merge 2 commits into
Kludex:mainfrom
gyanu2507:fix/parse-options-header-unicode
Open

Accept Unicode str values in parse_options_header#321
gyanu2507 wants to merge 2 commits into
Kludex:mainfrom
gyanu2507:fix/parse-options-header-unicode

Conversation

@gyanu2507

@gyanu2507gyanu2507 commented Aug 22, 2026

Copy link
Copy Markdown

parse_options_header already takes str | bytes | None, but a str with characters outside Latin-1 raises UnicodeEncodeError. That's the filename case people actually hit:

parse_options_header('form-data; name="upload"; filename="中文.doc"')

Bytes (the WSGI path) were already fine. For str this encodes as Latin-1 when it fits and falls back to UTF-8 otherwise, so the public API matches its type hint.

The issue asked which of the three options you wanted. I went with supporting Unicode str rather than a clearer error, because the signature already accepts str and that's what callers pass for filenames. Happy to switch to a dedicated error if you'd rather keep the Latin-1-only contract explicit.

Fixes#319

Review in cubic

The function already takes str, but encoding as latin-1 raised UnicodeEncodeError for filenames like 中文.doc. Fall back to UTF-8 when latin-1 cannot represent the value.
@codspeed-hq

codspeed-hqBot commented Aug 22, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing gyanu2507:fix/parse-options-header-unicode (4b35e58) with main (d9cb4c6)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-aicubic-dev-aiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

You’re at about 97% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Re-trigger cubic

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant

@gyanu2507