From 9652bbda5981cc7271a61d54bb322cd60ed9e189 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sun, 16 Aug 2026 23:17:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(html):=20=E6=AD=A3=E6=96=9C=E6=9D=A0=20UNC?= =?UTF-8?q?=20=E8=B7=AF=E5=BE=84=E5=9C=A8=E5=8C=B9=E9=85=8D=E6=AD=A3?= =?UTF-8?q?=E6=96=9C=E6=9D=A0=20cwd=20=E6=97=B6=E4=B9=9F=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=A0=87=E8=AE=B0=EF=BC=88=E5=9B=9E=E5=BA=94=20Codex=20P2=20#2?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 cwd 与产出路径都是 //server/share/... 形式时,此前两个 isWindowsStylePath 都为 false 而漏掉 '//' 标记,win32 解码后落在当前 盘符被 isWithin 拒绝。现按 review 建议:'//' 路径仅在其 '//' cwd 匹配时 视为 UNC;POSIX 会话的 '//' 绝对路径仍保持无标记。 --- src/client/api.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/client/api.ts b/src/client/api.ts index b1e72d1..194473b 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -212,6 +212,13 @@ function fileUrl(scope: SessionScope, path: string, download: boolean): string { return `/sidebar/file?${params.toString()}` } +/** A forward-slash UNC share (`//server/share/...`) — ambiguous with a POSIX + * absolute path, so it only counts as Windows-style when the session cwd is + * itself a forward-slash UNC (see htmlUrl). */ +function isForwardSlashUnc(path: string): boolean { + return /^\/\/[^/]/.test(path) +} + /** * Absolute URL of the HTML preview route (see html-route.ts): the path is * fully encoded so the previewed page's relative assets resolve back into @@ -220,10 +227,14 @@ function fileUrl(scope: SessionScope, path: string, download: boolean): string { * from the host OS, so no client-side platform detection is used), extended * by the file path itself: an unambiguous backslash UNC path keeps its '//' * marker even while the cwd is still hydrating or arrives in forward-slash - * form. Forward-slash `//` paths stay ambiguous without a Windows-style cwd, - * so they are deliberately NOT marked on their own — a POSIX session keeps - * them as ordinary absolute paths. + * form. A forward-slash `//` path is only marked when the cwd is itself a + * forward-slash UNC — a POSIX session keeps `//server/share/...` as an + * ordinary absolute path. */ export function htmlUrl(scope: SessionScope, path: string): string { - return encodeHtmlUrl(scope.sessionId, path, isWindowsStylePath(scope.cwd ?? '') || isWindowsStylePath(path)) + const cwd = scope.cwd ?? '' + const windowsPathStyle = isWindowsStylePath(cwd) + || isWindowsStylePath(path) + || (isForwardSlashUnc(path) && isForwardSlashUnc(cwd)) + return encodeHtmlUrl(scope.sessionId, path, windowsPathStyle) }