Files
ConvertX/tests/validatePath.test.ts
T
Emrik Östling 866510373b sync commits from swe-productivity study (#616)
Co-authored-by: Jennifer Wang <jennifer123wang@gmail.com>
Co-authored-by: strawberry-raccoon <253751817+strawberry-raccoon@users.noreply.github.com>
2026-08-19 22:48:25 +02:00

35 lines
1010 B
TypeScript

import { expect, test, describe } from "bun:test";
import { isSafePath } from "../src/helpers/validatePath";
describe("isSafePath", () => {
test("should allow no slash", () => {
const path = "cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow safe slash", () => {
const path = "dir/cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow leading slash", () => {
const path = "/dir/cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should allow leading dots", () => {
const path = "dir/..cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(true);
});
test("should disallow parent", () => {
const path = "../cat.jpg";
const result = isSafePath("./job/", `./job/${path}`);
expect(result).toEqual(false);
});
});