Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

727 B
Raw Blame
import path from "node:path";
export function sanitizeUntrustedFileName(fileName, fallbackName) {
    const trimmed = typeof fileName === "string" ? fileName.trim() : "";
    if (!trimmed) {
        return fallbackName;
    }
    let base = path.posix.basename(trimmed);
    base = path.win32.basename(base);
    let cleaned = "";
    for (let i = 0; i < base.length; i++) {
        const code = base.charCodeAt(i);
        if (code < 0x20 || code === 0x7f) {
            continue;
        }
        cleaned += base[i];
    }
    base = cleaned.trim();
    if (!base || base === "." || base === "..") {
        return fallbackName;
    }
    if (base.length > 200) {
        base = base.slice(0, 200);
    }
    return base;
}