From 6358aae024ed8f1d0270a8590fdb009b4906f061 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 2 Mar 2026 21:55:03 +0000 Subject: [PATCH] refactor(infra): share windows path normalization helper --- src/agents/path-policy.ts | 12 +----------- src/infra/path-guards.ts | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/agents/path-policy.ts b/src/agents/path-policy.ts index 042cff7ff4f..be0e1ffd7ed 100644 --- a/src/agents/path-policy.ts +++ b/src/agents/path-policy.ts @@ -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; diff --git a/src/infra/path-guards.ts b/src/infra/path-guards.ts index 751da0a9db0..a2f88a1532c 100644 --- a/src/infra/path-guards.ts +++ b/src/infra/path-guards.ts @@ -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);