From b514996208a084e02cf4b75ab638ca54eb183619 Mon Sep 17 00:00:00 2001 From: Daniel <57051444+daniel-lxs@users.noreply.github.com> Date: Mon, 12 Jan 2026 18:49:37 -0500 Subject: [PATCH] fix(path): return empty string from getReadablePath when path is empty - ROO-437 (#10638) --- src/utils/__tests__/path.spec.ts | 9 +++++++-- src/utils/path.ts | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/path.spec.ts b/src/utils/__tests__/path.spec.ts index a8cf84b68c..d0a79c3751 100644 --- a/src/utils/__tests__/path.spec.ts +++ b/src/utils/__tests__/path.spec.ts @@ -153,8 +153,13 @@ describe("Path Utilities", () => { expect(getReadablePath(desktop, filePath)).toBe(filePath.toPosix()) }) - it("should handle undefined relative path", () => { - expect(getReadablePath(cwd)).toBe("project") + it("should return empty string when relative path is undefined", () => { + expect(getReadablePath(cwd)).toBe("") + }) + + it("should return cwd basename when relative path is empty string", () => { + // Empty string resolves to cwd, which returns basename + expect(getReadablePath(cwd, "")).toBe("project") }) it("should handle parent directory traversal", () => { diff --git a/src/utils/path.ts b/src/utils/path.ts index 48e2ce6673..c1f4909995 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -80,7 +80,12 @@ function normalizePath(p: string): string { } export function getReadablePath(cwd: string, relPath?: string): string { - relPath = relPath || "" + // If relPath is undefined, return empty string instead of allowing path.resolve + // to return cwd (which would then show misleading cwd basename in UI) + if (relPath === undefined) { + return "" + } + // path.resolve is flexible in that it will resolve relative paths like '../../' to the cwd and even ignore the cwd if the relPath is actually an absolute path const absolutePath = path.resolve(cwd, relPath) if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) {