fix(path): return empty string from getReadablePath when path is empty - ROO-437 (#10638)

This commit is contained in:
Daniel 2026-01-12 18:49:37 -05:00 committed by GitHub
parent 621d9500de
commit b514996208
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -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", () => {

View file

@ -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"))) {