@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
33import { mockProcessPlatform } from "../test-utils/vitest-spies.js" ;
44import {
55 isPathInside ,
6+ isPathStrictlyInside ,
67 normalizeWindowsPathForComparison ,
78 normalizeWindowsPathPreservingCase ,
89} from "./path-guards.js" ;
@@ -60,6 +61,7 @@ describe("isPathInside", () => {
6061 [ "/workspace/root" , "/workspace/root" , true ] ,
6162 [ "/workspace/root" , "/workspace/root/nested/file.txt" , true ] ,
6263 [ "/workspace/root" , "/workspace/root/..file.txt" , true ] ,
64+ [ "/workspace/root" , "/workspace/root/..cache/cache.json" , true ] ,
6365 [ "/workspace/root" , "/workspace/root/../escape.txt" , false ] ,
6466 [ "/workspace/root" , "/workspace/rootless/file.txt" , false ] ,
6567 [ "/workspace/root" , "/workspace/root/a/b/c/d/e/file.txt" , true ] ,
@@ -88,3 +90,26 @@ describe("isPathInside", () => {
8890 }
8991 } ) ;
9092} ) ;
93+
94+ describe ( "isPathStrictlyInside" , ( ) => {
95+ it . each ( [
96+ [ "/workspace/root" , "/workspace/root" , false ] ,
97+ [ "/workspace/root" , "/workspace/root/child" , true ] ,
98+ [ "/workspace/root" , "/workspace/root/..cache/cache.json" , true ] ,
99+ [ "/workspace/root" , "/workspace/root/../escape" , false ] ,
100+ ] ) ( "checks strict posix containment %s -> %s" , ( basePath , targetPath , expected ) => {
101+ expect ( isPathStrictlyInside ( basePath , targetPath ) ) . toBe ( expected ) ;
102+ } ) ;
103+
104+ it ( "uses win32 path semantics for strict containment checks" , ( ) => {
105+ setPlatform ( "win32" ) ;
106+
107+ for ( const [ basePath , targetPath , expected ] of [
108+ [ String . raw `C:\workspace\root` , String . raw `C:\workspace\root` , false ] ,
109+ [ String . raw `C:\workspace\root` , String . raw `C:\workspace\root\..cache\file.txt` , true ] ,
110+ [ String . raw `C:\workspace\root` , String . raw `D:\workspace\root\file.txt` , false ] ,
111+ ] as const ) {
112+ expect ( isPathStrictlyInside ( basePath , targetPath ) ) . toBe ( expected ) ;
113+ }
114+ } ) ;
115+ } ) ;
0 commit comments