fix: keep POSIX sibling paths out of home-relative CLI displays (#162800)

* test: preserve POSIX backslashes at home path boundaries

* fix: preserve literal backslashes in POSIX home path displays

* test: format POSIX home boundary regression
This commit is contained in:
Ben.Li 2026-10-02 02:35:01 +08:00 • committed by GitHub
parent ccbd3b58f2
commit 4487ee82aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View file

@ -10,7 +10,10 @@ export function shortenPathWithHome(
if (input === home) {
return prefix;
}
if (input.startsWith(`${home}/`) || input.startsWith(`${home}\\`)) {
if (
input.startsWith(`${home}/`) ||
(process.platform === "win32" && input.startsWith(`${home}\\`))
) {
return `${prefix}${input.slice(home.length)}`;
}
if (process.platform === "win32" && path.win32.isAbsolute(input) && isPathInside(home, input)) {

View file

@ -173,9 +173,13 @@ describe("shortenHomePath", () => {
},
);
it.skipIf(process.platform === "win32")("keeps POSIX home matching case-sensitive", () => {
it.skipIf(process.platform === "win32")("preserves POSIX home path boundaries and case", () => {
withEnv({ OPENCLAW_HOME: "/srv/OpenClaw-Home", HOME: "/home/other" }, () => {
expect(shortenHomePath("/srv/openclaw-home/workspace")).toBe("/srv/openclaw-home/workspace");
expect(shortenHomePath("/srv/OpenClaw-Home\\workspace")).toBe(
"/srv/OpenClaw-Home\\workspace",
);
expect(shortenHomePath("/srv/OpenClaw-Home/work\\space")).toBe("$OPENCLAW_HOME/work\\space");
});
});