Skip to content

fix: encode Unicode filenames in Content-Disposition headers#39

Merged
tofran merged 2 commits intosignifica:mainfrom
jifang:bugs/filename-unicode
May 6, 2025
Merged

fix: encode Unicode filenames in Content-Disposition headers#39
tofran merged 2 commits intosignifica:mainfrom
jifang:bugs/filename-unicode

Conversation

@jifang
Copy link
Copy Markdown

@jifang jifang commented May 6, 2025

Previously, the server failed to handle APK filenames containing non-Latin characters (e.g., Chinese) due to HTTP header encoding limitations. The latin-1 requirement for headers caused UnicodeEncodeError when returning filenames with Unicode characters.

This change:

  1. Uses urllib.parse.quote() to percent-encode Unicode filenames
  2. Adopts RFC 5987 filename*= syntax with UTF-8 encoding
  3. Ensures compatibility with browsers while preserving original filenames

Example:

  • Old: filename=测试.apk → Broken (invalid header)
  • New: filename*=UTF-8''%E6%B5%8B%E8%AF%95.apk → Works (decodes as "测试.apk")

Fixes #38

Previously, the server failed to handle APK filenames containing non-Latin
characters (e.g., Chinese) due to HTTP header encoding limitations. The
`latin-1` requirement for headers caused `UnicodeEncodeError` when returning
filenames with Unicode characters.

This change:
1. Uses `urllib.parse.quote()` to percent-encode Unicode filenames
2. Adopts RFC 5987 `filename*=` syntax with UTF-8 encoding
3. Ensures compatibility with browsers while preserving original filenames

Example:
- Old: `filename=测试.apk` → Broken (invalid header)
- New: `filename*=UTF-8''%E6%B5%8B%E8%AF%95.apk` → Works (decodes as "测试.apk")

Fixes significa#38
Copy link
Copy Markdown
Member

@tofran tofran left a comment

Choose a reason for hiding this comment

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

This is great! Thank you

@tofran tofran force-pushed the bugs/filename-unicode branch from 7eeb695 to 25da4af Compare May 6, 2025 12:59
@tofran tofran merged commit 3a0c337 into significa:main May 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Unicode app name handling causes HTTP 500 errors in file downloads

2 participants