fix(feishu): recover Chinese filenames from Latin-1 mojibake in Content-Disposition#1059
Open
BingqingLyu wants to merge 2 commits into
Open
fix(feishu): recover Chinese filenames from Latin-1 mojibake in Content-Disposition#1059BingqingLyu wants to merge 2 commits into
BingqingLyu wants to merge 2 commits into
Conversation
added 2 commits
March 30, 2026 11:00
…nt-Disposition Node.js HTTP parser decodes header values as ISO-8859-1 (per RFC 7230). When Feishu returns a Content-Disposition header with a UTF-8 filename in the plain `filename` parameter (without `filename*=UTF-8'...`), each multibyte UTF-8 character becomes multiple Latin-1 code points, producing garbled names like "æµ_è_æ_ä_2.txt" instead of "何不同舟渡_2.txt". Add tryRecoverLatin1AsUtf8() which detects the mojibake pattern (all chars in U+0000–U+00FF range) and attempts to reconstruct the original UTF-8 string from the byte values. The recovery is skipped for pure ASCII strings (fast path) and strings that already contain non-Latin-1 characters. Closes openclaw#48388
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
Content-Disposition: attachment; filename="何不同舟渡_2.txt"using the plainfilenameparameter (without RFC 5987filename*=UTF-8'...), each 3-byte UTF-8 Chinese character becomes 3 separate Latin-1 characters.tryRecoverLatin1AsUtf8()which detects the mojibake pattern (all chars in U+0000–U+00FF range, contains non-ASCII) and reconstructs the original UTF-8 string. The recovery is safely skipped for pure ASCII strings and strings with genuine non-Latin-1 Unicode characters.Change Type
Scope
Linked Issue
User-visible / Behavior Changes
Before: File "何不同舟渡_2.txt" → saved as "æµ_è_æ_ä_2---uuid.txt"
After: File "何不同舟渡_2.txt" → saved as "何不同舟渡_2---uuid.txt"
Security Impact
None. Pure string transformation with no external I/O.
Evidence
Compatibility
filename*=UTF-8'...path (already correct) is tried first.Risks
Minimal. The recovery only fires when ALL characters are in the Latin-1 range AND the bytes form valid UTF-8. If the bytes are not valid UTF-8, the original string is returned unchanged.
[AI-assisted development by OpenClaw agent 虾干 🦐]