Skip to content

Commit 3128340

Browse files
committed
fix(media): use truncateUtf16Safe for sanitized filename truncation
Replace .slice(0, 60) with truncateUtf16Safe() to prevent UTF-16 surrogate pair corruption in cross-platform filenames.
1 parent e595a8c commit 3128340

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/media/store.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { detectMime, extensionForMime } from "@openclaw/media-core/mime";
1616
import { hasHttpUrlPrefix } from "@openclaw/net-policy/url-protocol";
1717
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
18+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
1819
import { toErrorObject } from "../infra/errors.js";
1920
import { fileStore } from "../infra/file-store.js";
2021
import { sanitizeUntrustedFileName } from "../infra/fs-safe-advanced.js";
@@ -124,7 +125,7 @@ function sanitizeFilename(name: string): string {
124125
}
125126
const sanitized = base.replace(/[^\p{L}\p{N}._-]+/gu, "_");
126127
// Collapse multiple underscores, trim leading/trailing, limit length
127-
return sanitized.replace(/_+/g, "_").replace(/^_|_$/g, "").slice(0, 60);
128+
return truncateUtf16Safe(sanitized.replace(/_+/g, "_").replace(/^_|_$/g, ""), 60);
128129
}
129130

130131
/** Restores the caller-facing filename from media-store paths with embedded UUID suffixes. */

0 commit comments

Comments
 (0)