34 lines
1018 B
TypeScript
34 lines
1018 B
TypeScript
// @vitest-environment node
|
|
import { describe, expect, it } from "vitest";
|
|
import { assessArchivePath } from "../../src/archive/paths";
|
|
|
|
describe("archive path policy", () => {
|
|
it.each([
|
|
"../escape.txt",
|
|
"/absolute.txt",
|
|
"C:/drive.txt",
|
|
"safe/../../escape",
|
|
"CON",
|
|
"file.txt:stream",
|
|
"trailing. ",
|
|
"invoice\u202egnp.exe",
|
|
])("blocks unsafe path %s", (path) =>
|
|
expect(assessArchivePath(path).safe).toBe(false),
|
|
);
|
|
|
|
it("normalizes Unicode and treats backslashes as cross-platform separators", () => {
|
|
const result = assessArchivePath("Folder\\cafe\u0301.txt");
|
|
expect(result.normalized).toBe("Folder/café.txt");
|
|
expect(result.safe).toBe(true);
|
|
expect(result.issues.map((issue) => issue.code)).toContain(
|
|
"BACKSLASH_PATH",
|
|
);
|
|
});
|
|
|
|
it("produces a conservative case-insensitive collision key", () => {
|
|
expect(assessArchivePath("Folder/Report.TXT").collisionKey).toBe(
|
|
assessArchivePath("folder/report.txt").collisionKey,
|
|
);
|
|
});
|
|
});
|