fs-safe/test/filename.test.ts
2026-05-05 11:08:33 +01:00

16 lines
585 B
TypeScript

import { describe, expect, it } from "vitest";
import { sanitizeUntrustedFileName } from "../src/filename.js";
describe("sanitizeUntrustedFileName", () => {
it("keeps only the basename and strips control characters", () => {
expect(sanitizeUntrustedFileName("../nested/rep\u0000ort.pdf", "fallback.bin")).toBe(
"report.pdf",
);
});
it("uses fallback for empty or path-alias names", () => {
expect(sanitizeUntrustedFileName(" ", "fallback.bin")).toBe("fallback.bin");
expect(sanitizeUntrustedFileName("..", "fallback.bin")).toBe("fallback.bin");
});
});