Skip to content

fix(feishu): decode RFC 5987 filename for file downloads#43983

Closed
guang384 wants to merge 32 commits into
openclaw:mainfrom
guang384:fix/issue-43840
Closed

fix(feishu): decode RFC 5987 filename for file downloads#43983
guang384 wants to merge 32 commits into
openclaw:mainfrom
guang384:fix/issue-43840

Conversation

@guang384

Copy link
Copy Markdown

Summary

Fixes #43840

Problem

When sending files with non-ASCII filenames (Chinese, Japanese, emoji) in Lark/Feishu, the filename appears URL-encoded (e.g., %E6%B5%8B%E8%AF%95.txt instead of 测试.txt).

Root Cause

The backend receives the Content-Disposition header with RFC 5987 encoded filename (filename*=UTF-8...) but fails to decode it using decodeURIComponent before storing/displaying.

Changes

  • Add decodeRfc5987Filename() helper function to decode percent-encoded filenames
  • Apply to file message display (line 437)
  • Apply to file download metadata (line 539)

Test

  1. Prepare a file with non-ASCII filename (e.g., 测试.pdf)
  2. Send the file via Lark/Feishu client
  3. Verify the filename displays correctly as 测试.pdf instead of URL-encoded string

Fixes openclaw#43840

- Add decodeRfc5987Filename() to decode percent-encoded filenames
- Apply to file message display (line 437)
- Apply to file download metadata (line 539)
@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS labels Mar 12, 2026
@greptile-apps

greptile-apps Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a decodeFeishuFilename() helper to extensions/feishu/src/bot.ts and applies it to all parsed.file_name usages, fixing the display of non-ASCII filenames (Chinese, Japanese, emoji) sent through Lark/Feishu. The function handles both plain percent-encoded filenames and the RFC 5987 filename*=charset'lang'encoded format.

All issues raised in previous review rounds have been addressed in this revision:

  • decodeURIComponent calls are guarded with try/catch in both the RFC 5987 and plain-filename branches.
  • The RFC 5987 charset matching is case-insensitive (/i flag), so utf-8, UTF-8, etc. all match.
  • Non-empty language tags (e.g. UTF-8'zh-CN'…) are correctly stripped by the [^']* capture in the regex.
  • The stale duplicate JSDoc has been removed; the current doc comment accurately describes what the function does.
  • The test file is a single clean describe block with no duplicate suites, no stray });, and no top-level it() calls.
  • A new test case ("decodes RFC 5987 with language tag") explicitly covers the language-tag path.

The CHANGELOG entry wording ("instead of using RFC 5987 format") is slightly imprecise — the implementation supports RFC 5987 in addition to plain URL-encoded names — but this is a cosmetic concern and does not affect correctness.

Confidence Score: 5/5

  • This PR is safe to merge; all previously flagged issues have been resolved and no new issues were found.
  • The helper is well-scoped with proper error handling, case-insensitive matching, and RFC 5987 language-tag support. The test suite covers the main paths including the RFC 5987-with-language-tag case. No regressions are expected since the function only changes behaviour for filenames that are either RFC 5987-prefixed or decode to a string containing non-ASCII characters.
  • No files require special attention.

Last reviewed commit: 734171e

Comment thread extensions/feishu/src/bot.ts Outdated
Comment thread extensions/feishu/src/bot.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88320de187

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts Outdated

@ademczuk ademczuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tackling the Feishu non-ASCII filename display issue. The problem is real and affects users with CJK filenames.

A few things to flag:

1. Stronger competing PR exists

#43916 by @ccsang addresses the same bug with a more comprehensive approach: exported/testable decoder function, 8 tests, CHANGELOG entry, and fixes across both bot.ts and media.ts (upload side as well as display). It also covers the UI tool cards. Given that #43916 is further along, it might be worth coordinating with that PR rather than duplicating effort.

2. The filename*=UTF-8'' prefix check is likely dead code

Feishu's JSON payloads send file_name as plain encodeURIComponent output (e.g. %E6%B5%8B%E8%AF%95.pdf), not the RFC 5987 format (filename*=UTF-8''%E6%B5%8B%E8%AF%95.pdf). RFC 5987 is an HTTP header encoding format, not a JSON payload format. The startsWith("filename*=UTF-8''") branch will never trigger for real Feishu messages, making that path dead code. The function should likely just call decodeURIComponent directly.

3. Missing try/catch around decodeURIComponent

decodeURIComponent throws URIError on malformed percent-encoded strings (e.g. truncated %E6%). In parseMediaKeys, the outer try/catch returns {} on any error, which would silently drop the fileKey and break file downloads for an otherwise valid file. A try/catch inside the decoder with a fallback to the raw string would be safer.

4. Function is private

decodeRfc5987Filename is scoped as a module-private function in bot.ts, which makes it impossible to unit test directly. Exporting it (as #43916 does) would allow focused tests.

5. No tests or CHANGELOG

Both are expected for user-facing bug fixes per CONTRIBUTING.md.

The core idea is sound. If #43916 stalls, addressing the points above would make this a solid alternative.

- Remove dead RFC 5987 code path (not used by Feishu JSON)
- Add try/catch for decodeURIComponent to prevent crashes
- Export function for unit testing
- Add CHANGELOG entry

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b493b2e5c

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 821a262e2e

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts Outdated
@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ 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".

@guang384

Copy link
Copy Markdown
Author

@greptileai review

Comment thread extensions/feishu/src/bot.ts Outdated
Comment thread extensions/feishu/src/bot.filename-decode.test.ts Outdated
guang384 and others added 2 commits March 16, 2026 20:47
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 415fa98b90

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d006d11f7

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts
@guang384

Copy link
Copy Markdown
Author

@codex review

@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c49d3624b9

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts Outdated
@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ 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".

@guang384

Copy link
Copy Markdown
Author

@greptileai review

@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7231b0d531

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts
@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ 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".

@guang384

Copy link
Copy Markdown
Author

@greptileai review

@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ 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".

@guang384

Copy link
Copy Markdown
Author

@greptileai review

@guang384

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ 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".

@guang384

Copy link
Copy Markdown
Author

@greptileai review

@guang384

Copy link
Copy Markdown
Author

Thanks @ademczuk for the review!

I've addressed all the Greptile feedback and the PR now has a 5/5 confidence score. The fix:

  • Decodes RFC 5987 filenames (including language tag)
  • Decodes plain percent-encoded non-ASCII filenames
  • Applies decoding to all media types consistently (image, file, audio, video, sticker)

I saw #43916 by @ccsang - that's a comprehensive solution too! Would be great to get either this or #43916 merged to fix the non-ASCII filename issue. Thanks!

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39e8811a3d

ℹ️ 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".

Comment thread CHANGELOG.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1d6839ccda

ℹ️ 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".

Comment thread extensions/feishu/src/bot.ts
@steipete

Copy link
Copy Markdown
Contributor

Closing this as implemented after Codex review.

Current main already fixes the reported Feishu filename symptom through the shipped upload-path change in v2026.3.12, and it also already decodes RFC 5987 download header filenames. This PR's extra JSON file_name decoding is therefore redundant against the current codebase.

What I checked:

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review notes: reviewed against 50e36983bb2d; fix evidence: release v2026.3.12.

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

Labels

channel: feishu Channel integration: feishu size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Filename Becomes URL-Encoded String After Sending Files in Lark/Feishu

3 participants