fix(feishu): encode non-ASCII filenames in file uploads#31328
fix(feishu): encode non-ASCII filenames in file uploads#31328Takhoffman merged 3 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a14f7a75ce
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
extensions/feishu/src/media.ts
Outdated
| const encoded = encodeURIComponent(base) | ||
| .replace(/'/g, "%27") | ||
| .replace(/\(/g, "%28") | ||
| .replace(/\)/g, "%29"); | ||
| return encoded + ext; |
There was a problem hiding this comment.
Encode non-ASCII extension bytes before upload
sanitizeFileNameForUpload only percent-encodes the basename and then appends ext unchanged, so filenames like 报告.数据 or 示例.测试 still send raw non-ASCII bytes in file_name. In those inputs, the new safeguard does not actually make the multipart metadata ASCII-safe, so uploads can still fail for a subset of non-ASCII filenames even after this fix.
Useful? React with 👍 / 👎.
Greptile SummaryAdds RFC 5987 percent-encoding for non-ASCII characters in Feishu file upload filenames, fixing silent upload failures. The implementation introduces a
The fix is applied in Confidence Score: 5/5
Last reviewed commit: a14f7a7 |
a14f7a7 to
b3b07c3
Compare
Feishu file uploads silently fail when file_name contains Chinese characters or special characters (em-dash, full-width brackets, etc.) because the multipart/form-data serialization requires 7-bit ASCII headers. Add sanitizeFileNameForUpload() that RFC 5987 percent-encodes the basename while preserving the file extension. ASCII-only filenames pass through unchanged. Fixes openclaw#31179 Made-with: Cursor
b3b07c3 to
3681204
Compare
|
PR #31328 - fix(feishu): encode non-ASCII filenames in file uploads (#31328) Merged after verification.
|
…) thanks @Kay-051 Verified: - pnpm test extensions/feishu/src/media.test.ts Co-authored-by: Kay-051 <210470990+Kay-051@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…) thanks @Kay-051 Verified: - pnpm test extensions/feishu/src/media.test.ts Co-authored-by: Kay-051 <210470990+Kay-051@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…) thanks @Kay-051 Verified: - pnpm test extensions/feishu/src/media.test.ts Co-authored-by: Kay-051 <210470990+Kay-051@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Summary
Fixes #31179
Feishu file uploads silently fail when
file_namecontains non-ASCII characters (Chinese, em-dash—, full-width brackets(), etc.). The multipart/form-data serialization sends raw UTF-8 bytes in header fields where RFC 2388 expects 7-bit ASCII, causing Feishu's API to treat the upload as text instead of an attachment.Changes
extensions/feishu/src/media.ts: AddsanitizeFileNameForUpload()that RFC 5987 percent-encodes the file basename while preserving the extension. ASCII-only filenames pass through unchanged. Applied inuploadFileFeishu()before the SDK call.extensions/feishu/src/media.test.ts: Add tests for:sanitizeFileNameForUpload()covering edge cases (no extension, mixed ASCII/non-ASCII, RFC 5987 special chars)Test Results
测试文档.pdfreport-2026.pdf报告—详情(2026).mdTest plan
vitest run extensions/feishu/src/media.test.ts)file_namefield',(,)) are properly encodedMade with Cursor