Skip to content

Commit d663c00

Browse files
committed
fix(path): return empty string from getReadablePath when path is empty
ROO-437: Prevent showing CWD basename when file path is empty/undefined When getReadablePath() was called with an empty or undefined path, it returned path.basename(cwd) (e.g., 'extracker'), which was misleading users into thinking the model was trying to write to a directory. Now it returns an empty string instead, so the UI shows nothing rather than a misleading directory name when the path is unavailable.
1 parent e23e1ec commit d663c00

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/utils/__tests__/path.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ describe("Path Utilities", () => {
153153
expect(getReadablePath(desktop, filePath)).toBe(filePath.toPosix())
154154
})
155155

156-
it("should handle undefined relative path", () => {
157-
expect(getReadablePath(cwd)).toBe("project")
156+
it("should return empty string when relative path is undefined or empty", () => {
157+
expect(getReadablePath(cwd)).toBe("")
158+
expect(getReadablePath(cwd, "")).toBe("")
159+
expect(getReadablePath(cwd, " ")).toBe("")
158160
})
159161

160162
it("should handle parent directory traversal", () => {

src/utils/path.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ function normalizePath(p: string): string {
8080
}
8181

8282
export function getReadablePath(cwd: string, relPath?: string): string {
83-
relPath = relPath || ""
83+
// If no path provided, return empty string instead of cwd basename
84+
// This prevents showing misleading directory names when a file path is expected
85+
if (!relPath || relPath.trim() === "") {
86+
return ""
87+
}
88+
8489
// 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
8590
const absolutePath = path.resolve(cwd, relPath)
8691
if (arePathsEqual(cwd, path.join(os.homedir(), "Desktop"))) {

0 commit comments

Comments
 (0)