Skip to content

Commit 9e1892f

Browse files
committed
Fix Windows tests after merge
1 parent efef400 commit 9e1892f

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

library/vulnerabilities/path-traversal/containsUnsafePathParts.test.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
containsUnsafePathPartsUrl,
55
} from "./containsUnsafePathParts";
66
import { fileURLToPath } from "url";
7+
import { isWindows } from "../../helpers/isWindows";
78

89
t.test("not a dangerous path", async () => {
910
t.same(containsUnsafePathParts("test.txt"), false);
@@ -45,14 +46,30 @@ t.test("it detects dangerous path parts for URLs", async () => {
4546
});
4647

4748
t.test("it only removes some chars from the URL", async () => {
48-
t.same(fileURLToPath("file:///.\t./test.txt"), "/test.txt");
49-
t.same(fileURLToPath("file:///.\n./test.txt"), "/test.txt");
50-
t.same(fileURLToPath("file:///.\r./test.txt"), "/test.txt");
51-
t.same(fileURLToPath("file:///.\0./test.txt"), "/.\0./test.txt");
52-
t.same(fileURLToPath("file:///.\u0000./test.txt"), "/.\u0000./test.txt");
53-
t.same(fileURLToPath("file:///.\v./test.txt"), "/.\v./test.txt");
54-
t.same(fileURLToPath("file:///.\f./test.txt"), "/.\f./test.txt");
55-
t.same(fileURLToPath("file:///.\b./test.txt"), "/.\b./test.txt");
56-
t.same(fileURLToPath("file:///.\t\t./test.txt"), "/test.txt");
57-
t.same(fileURLToPath("file:///.\t\n./test.txt"), "/test.txt");
49+
if (!isWindows) {
50+
t.same(fileURLToPath("file:///.\t./test.txt"), "/test.txt");
51+
t.same(fileURLToPath("file:///.\n./test.txt"), "/test.txt");
52+
t.same(fileURLToPath("file:///.\r./test.txt"), "/test.txt");
53+
t.same(fileURLToPath("file:///.\0./test.txt"), "/.\0./test.txt");
54+
t.same(fileURLToPath("file:///.\u0000./test.txt"), "/.\u0000./test.txt");
55+
t.same(fileURLToPath("file:///.\v./test.txt"), "/.\v./test.txt");
56+
t.same(fileURLToPath("file:///.\f./test.txt"), "/.\f./test.txt");
57+
t.same(fileURLToPath("file:///.\b./test.txt"), "/.\b./test.txt");
58+
t.same(fileURLToPath("file:///.\t\t./test.txt"), "/test.txt");
59+
t.same(fileURLToPath("file:///.\t\n./test.txt"), "/test.txt");
60+
} else {
61+
t.same(fileURLToPath("file://X:/.\t./test.txt"), "X:\\test.txt");
62+
t.same(fileURLToPath("file://X:/.\n./test.txt"), "X:\\test.txt");
63+
t.same(fileURLToPath("file://X:/.\r./test.txt"), "X:\\test.txt");
64+
t.same(fileURLToPath("file://X:/.\0./test.txt"), "X:\\.\0.\\test.txt");
65+
t.same(
66+
fileURLToPath("file://X:/.\u0000./test.txt"),
67+
"X:\\.\u0000.\\test.txt"
68+
);
69+
t.same(fileURLToPath("file://X:/.\v./test.txt"), "X:\\.\v.\\test.txt");
70+
t.same(fileURLToPath("file://X:/.\f./test.txt"), "X:\\.\f.\\test.txt");
71+
t.same(fileURLToPath("file://X:/.\b./test.txt"), "X:\\.\b.\\test.txt");
72+
t.same(fileURLToPath("file://X:/.\t\t./test.txt"), "X:\\test.txt");
73+
t.same(fileURLToPath("file://X:/.\t\n./test.txt"), "X:\\test.txt");
74+
}
5875
});

0 commit comments

Comments
 (0)