refactor(infra): share windows path normalization helper

This commit is contained in:
Peter Steinberger
2026-03-02 21:55:03 +00:00
parent 55a2d12f40
commit 6358aae024
2 changed files with 2 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
import path from "node:path";
import { normalizeWindowsPathForComparison } from "../infra/path-guards.js";
import { resolveSandboxInputPath } from "./sandbox-paths.js";
type RelativePathOptions = {
@@ -8,17 +9,6 @@ type RelativePathOptions = {
includeRootInError?: boolean;
};
function normalizeWindowsPathForComparison(input: string): string {
let normalized = path.win32.normalize(input);
if (normalized.startsWith("\\\\?\\")) {
normalized = normalized.slice(4);
if (normalized.toUpperCase().startsWith("UNC\\")) {
normalized = `\\\\${normalized.slice(4)}`;
}
}
return normalized.replaceAll("/", "\\").toLowerCase();
}
function toRelativePathUnderRoot(params: {
root: string;
candidate: string;

View File

@@ -3,7 +3,7 @@ import path from "node:path";
const NOT_FOUND_CODES = new Set(["ENOENT", "ENOTDIR"]);
const SYMLINK_OPEN_CODES = new Set(["ELOOP", "EINVAL", "ENOTSUP"]);
function normalizeWindowsPathForComparison(input: string): string {
export function normalizeWindowsPathForComparison(input: string): string {
let normalized = path.win32.normalize(input);
if (normalized.startsWith("\\\\?\\")) {
normalized = normalized.slice(4);