mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix(path): return empty string from getReadablePath when path is empty - ROO-437 (#10638)
This commit is contained in:
parent
621d9500de
commit
b514996208
2 changed files with 13 additions and 3 deletions
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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"))) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue