Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/utils/__tests__/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
7 changes: 6 additions & 1 deletion src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand Down
Loading