fix(html): 正斜杠 UNC 路径在匹配正斜杠 cwd 时也保留标记(回应 Codex P2 #2)

当 cwd 与产出路径都是 //server/share/... 形式时,此前两个
isWindowsStylePath 都为 false 而漏掉 '//' 标记,win32 解码后落在当前
盘符被 isWithin 拒绝。现按 review 建议:'//' 路径仅在其 '//' cwd 匹配时
视为 UNC;POSIX 会话的 '//' 绝对路径仍保持无标记。
This commit is contained in:
Menghuan1918
2026-08-16 23:24:53 +08:00
parent 0052061a72
commit 9652bbda59
+15 -4
View File
@@ -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)
}