fix: handle non-ASCII filenames in file send#143
Conversation
Two issues caused file sends with non-ASCII filenames (e.g. CJK characters) to silently fail: 1. paste-file: The file:// URI passed to xclip contained raw non-ASCII bytes. WeChat's Qt under POSIX locale cannot resolve such URIs. Fix: detect non-ASCII paths and copy the file to an ASCII-safe temp path before pasting. 2. messages.rs: If std::fs::write failed (or base64 decode failed), file_path stayed None and the handler returned success:true without actually sending anything. Fix: sanitize the filename to ASCII for the temp path, and return proper error responses on failure instead of silently succeeding.
thisnick
left a comment
There was a problem hiding this comment.
Good fix — both issues are real and the approach is sound. A few notes:
docker/tools/paste-file
The grep -qP '[^\x00-\x7F]' pattern requires grep with PCRE support (-P). GNU grep has it but some minimal Docker base images ship BusyBox grep which doesn't. Consider using a portable alternative:
# Portable: checks if path survives ASCII round-trip
if [ "$ABS_PATH" != "$(echo "$ABS_PATH" | LC_ALL=C tr -cd '\\0-\\177')" ]; thenOr just check the exit code of iconv:
if ! echo "$ABS_PATH" | iconv -f UTF-8 -t ASCII >/dev/null 2>&1; thenThe 10-second cleanup window is probably fine for normal use, but a large file paste could theoretically race. Not blocking — just worth noting.
messages.rs
The error handling improvement is a clear win. One minor nit: the safe_name mapping strips the extension separator dot along with CJK chars if the original filename has a CJK stem + ASCII extension (e.g. 遗憾.pdf → ____.pdf). That's fine functionally since it's a temp path, but worth a comment clarifying intent.
Changeset
Please add a changeset for this fix so it gets picked up in the next release:
npx changesetSelect patch for agent-server-rust (and whichever package owns paste-file if it's versioned separately). Add a brief description matching the PR title.
|
(Apologies for the duplicate review comments above — please refer to the last one only.) |
…changeset - Replace GNU grep -P with iconv for portable non-ASCII detection (paste-file) - Add comment clarifying dot preservation in safe_name sanitization (messages.rs) - Add patch changeset for @agent-wechat/agent-server
|
Thanks for the review! Addressed all three points:
Pushed in 5b8ef39. |
Problem
Sending files with non-ASCII filenames (e.g. CJK characters like
遗憾-注释版.pdf) via the/api/messages/sendendpoint silently fails — the API returns{"success": true}but the file is never actually sent through WeChat.Root Cause
Two separate issues:
1.
paste-filescript: raw non-ASCII bytes infile://URIThe script builds a
file://URI from the absolute path and passes it toxclip. When the path contains non-ASCII characters (CJK, etc.), WeChat's Qt under POSIX locale cannot resolve the URI, so the clipboard paste silently does nothing.2.
messages.rs: silent failure on file write/decode errorsIf
base64::decodeorstd::fs::writefails,file_pathremainsNone. The handler then runs the send plan with no file, finishes successfully, and returns{"success": true}— even though nothing was sent.Fix
docker/tools/paste-file/tmp/paste_safe_<timestamp>.<ext>)file://URIpackages/agent-server-rust/src/router/messages.rs_) for the temp pathsuccess: false+ error message) when base64 decode or file write fails, instead of silently succeedingTesting
Verified on agent-wechat 0.11.12 (Docker, linux-arm64):
test.pdf(ASCII)遗憾-注释版.pdf(CJK)中文测试.pdf(CJK)