fix: handle non-ASCII filenames in Content-Disposition headers#79
Merged
jamiepine merged 1 commit intojamiepine:mainfrom Feb 23, 2026
Merged
Conversation
The export endpoints (export-audio, export generation, export profile, export story) crash with `'latin-1' codec can't encode characters` when the generated text or profile/story name contains non-ASCII characters (e.g. Cyrillic, Chinese, Arabic). Root cause: Python's `str.isalnum()` passes Unicode letters through to the filename, but HTTP headers are encoded as latin-1 by the ASGI server, which cannot represent characters outside the 0-255 range. Fix: introduce `_safe_content_disposition()` helper that builds a standards-compliant header with an ASCII-only `filename` fallback and a RFC 5987 `filename*=UTF-8''...` parameter for Unicode-capable clients. Fixes jamiepine#68 Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
'latin-1' codec can't encode characterswhen generated text or profile/story names contain non-ASCII characters (Cyrillic, Chinese, Arabic, etc.)_safe_content_disposition()helper that builds standards-compliant headers with an ASCII-onlyfilenamefallback and RFC 5987filename*=UTF-8''...parameter for Unicode-capable clientsexport_profile,export_generation,export_generation_audio,export_story_audioRoot cause
Python 3's
str.isalnum()returnsTruefor Unicode alphanumeric characters, so Cyrillic/Chinese/etc. letters pass through the filename filter. However, HTTP response headers are encoded aslatin-1by the ASGI server (uvicorn/starlette), which cannot represent characters outside the 0–255 range.Fix
Introduced
_safe_content_disposition(disposition_type, filename)that:filenameparameter (latin-1 safe fallback)filename*=UTF-8''<percent-encoded>parameter per RFC 5987 so modern browsers can still display the original Unicode filenameTest plan
Fixes #68