fix(ui): 修复 Windows Home 路径缩写 - #356
Conversation
tt-a1i
left a comment
There was a problem hiding this comment.
Thanks for the focused fix. The common Windows backslash case is covered and the current CI is green, but the containment check still needs to be path-flavor aware. Please address the inline cross-platform regression and add the two boundary tests before this merges.
| export function formatDirectory(cwd: string, home = homedir()) { | ||
| if (cwd === home) return "~"; | ||
| const display = cwd.startsWith(`${home}/`) ? `~/${relative(home, cwd)}` : cwd; | ||
| const separator = cwd.startsWith(home) ? cwd[home.length] : undefined; |
There was a problem hiding this comment.
This accepts both / and \\ as separators on every platform. On POSIX, \\ is an ordinary filename character, so formatDirectory("/Users/adam\\\\project", "/Users/adam") incorrectly returns ~/project even though that cwd is not inside the Home directory. The raw prefix check is also case-sensitive on Windows: c:\\\\users\\\\adam\\\\project is not shortened against C:\\\\Users\\\\Adam, although Windows treats them as the same path. Please make containment platform/path-flavor aware (for example, use the appropriate win32.relative or posix.relative behind an injectable path flavor), reject parent/absolute relative results, normalize separators only for display, and add regression tests for both cases.
Problem
在 Windows 上,
homedir()和当前工作目录使用反斜杠(\),而formatDirectory只检查${home}/。因此 Home 目录下的工作目录无法缩写为~/...,页脚会显示完整绝对路径。关联 Issue:#335。
Value
修复 Windows 页脚当前目录显示,减少无用的绝对路径占用,同时保持 POSIX 路径、Home 根目录和 Home 外路径的现有行为。
Approach
/和\\分隔符。/展示格式。~,并避免把C:\\Users\\Adam2等相邻路径误判为 Home 子路径。Validation
node --test tests/extensions/ui-customization/footer.test.ts:14/14 通过。bun run check:通过(配置契约、纪律检查、Web 语法、格式、Lint、TypeScript)。git diff --check:通过。bun run test:Windows 本地完整套件仍遇到已有的background-terminals进程测试失败并挂起;相关问题与本 PR 修改的页脚文件无关。Impact
~/...,其他路径行为不变。Fixes #335