Skip to content

Commit 12e9b7d

Browse files
authored
fix: Root path check on Windows is now case-insensitive (#49)
Plus linting fixes Fixes #17
1 parent a3beade commit 12e9b7d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Context.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export default class Context {
8484
}
8585

8686
return this.allowedRootPaths.some((rootPath) => {
87+
if (process.platform === "win32") {
88+
return absolutePath.toUpperCase().startsWith(rootPath.toUpperCase()); // case-insensitive due to Windows
89+
}
8790
return absolutePath.startsWith(rootPath);
8891
});
8992
}

test/lib/Context.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,21 @@ test("normalizePath throws error when realpath fails", async (t) => {
301301
const error = await t.throwsAsync(() => context.normalizePath(inputPath));
302302
t.is(error, fsError);
303303
});
304+
305+
test("isInsideRoots compares Windows drive letter case-insensitively", (t) => {
306+
const {Context} = t.context;
307+
const context = new Context();
308+
309+
// Only a meaningful assertion on Windows. On other platforms just mark as passed.
310+
if (process.platform !== "win32") {
311+
t.pass();
312+
return;
313+
}
314+
315+
// Lowercase root, uppercase path
316+
const lowerRoot = "c:\\caseinsensitive\\root";
317+
context.setRoots([{uri: pathToFileURL(lowerRoot).toString()}]);
318+
319+
const upperPath = "C:\\CaseInsensitive\\Root\\subdir\\file.txt";
320+
t.true(context.isInsideRoots(upperPath));
321+
});

0 commit comments

Comments
 (0)