Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid empty user display paths #9312

Merged
merged 1 commit into from
Nov 21, 2024
Merged
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
10 changes: 10 additions & 0 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl<T: AsRef<Path>> Simplified for T {
return path.display();
}

if path.as_os_str() == "" {
// Avoid printing an empty string for the current directory
return Path::new(".").display();
}

// Attempt to strip the current working directory, then the canonicalized current working
// directory, in case they differ.
let path = path.strip_prefix(CWD.simplified()).unwrap_or(path);
Expand All @@ -85,6 +90,11 @@ impl<T: AsRef<Path>> Simplified for T {
.strip_prefix(base.as_ref())
.unwrap_or_else(|_| path.strip_prefix(CWD.simplified()).unwrap_or(path));

if path.as_os_str() == "" {
// Avoid printing an empty string for the current directory
return Path::new(".").display();
}

path.display()
}

Expand Down
Loading