|
4 | 4 | containsUnsafePathPartsUrl, |
5 | 5 | } from "./containsUnsafePathParts"; |
6 | 6 | import { fileURLToPath } from "url"; |
| 7 | +import { isWindows } from "../../helpers/isWindows"; |
7 | 8 |
|
8 | 9 | t.test("not a dangerous path", async () => { |
9 | 10 | t.same(containsUnsafePathParts("test.txt"), false); |
@@ -45,14 +46,30 @@ t.test("it detects dangerous path parts for URLs", async () => { |
45 | 46 | }); |
46 | 47 |
|
47 | 48 | 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 | + } |
58 | 75 | }); |
0 commit comments