fix: resolve paths in validation for Windows compatibility
normalizeForCompare and isPathWithinRoot now use path.resolve()
to ensure consistent drive-letter prefix on Windows. Previously
path.normalize('/foo') gave '\foo' (no drive letter) while
path.resolve('/foo') gives 'C:\foo', causing containment checks
to fail on Windows CI.
This commit is contained in:
parent
ccee484adc
commit
20d563d737
1 changed files with 4 additions and 2 deletions
|
|
@ -62,12 +62,14 @@ export interface PathValidationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeForCompare(input: string, isWindows: boolean): string {
|
function normalizeForCompare(input: string, isWindows: boolean): string {
|
||||||
const normalized = path.normalize(input);
|
const normalized = path.resolve(path.normalize(input));
|
||||||
return isWindows ? normalized.toLowerCase() : normalized;
|
return isWindows ? normalized.toLowerCase() : normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPathWithinRoot(targetPath: string, rootPath: string): boolean {
|
export function isPathWithinRoot(targetPath: string, rootPath: string): boolean {
|
||||||
return targetPath === rootPath || targetPath.startsWith(rootPath + path.sep);
|
const target = path.resolve(targetPath);
|
||||||
|
const root = path.resolve(rootPath);
|
||||||
|
return target === root || target.startsWith(root + path.sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveRealPathIfExists(inputPath: string): string | null {
|
function resolveRealPathIfExists(inputPath: string): string | null {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue