fix(onebot): percent-decode file URL basenames on upload (#354)

send_group_msg / send_private_msg with a file segment that only has
file:// (no name/filename) used url.split('/').pop() as the upload
name, so percent-encoded CJK paths uploaded as
%E6%B5%8B%E8%AF%95%E6%96%87%E4%BB%B6.xlsx. Derive the fallback through
guessFileNameFromUrl, which decodeURIComponent's the path basename
(invalid encodings are left as-is). An explicit name still wins.

Fixes #354
This commit is contained in:
DrSmoothl committed 2026-08-13 11:02:02 +08:00
1 parent 5c2f620c54
commit 2f5065545a
5 files changed
+81 -5

No files matched your search

+8 -2
View File
@@ -252,11 +252,17 @@ export async function loadBinarySource(
return { bytes, fileName };
}
function guessFileNameFromUrl(url: string): string {
export function guessFileNameFromUrl(url: string): string {
const queryPos = url.search(/[?#]/);
const pathPart = queryPos >= 0 ? url.slice(0, queryPos) : url;
const lastSlash = pathPart.lastIndexOf('/');
return lastSlash >= 0 ? pathPart.slice(lastSlash + 1) : '';
const raw = lastSlash >= 0 ? pathPart.slice(lastSlash + 1) : '';
if (!raw) return '';
try {
return decodeURIComponent(raw);
} catch {
return raw;
}
}
// --- Hashing ---