Skip to content

Commit 921b6c0

Browse files
committed
If HOME is empty, use the fallback instead
1 parent 4d08223 commit 921b6c0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

library/std/src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl Error for JoinPathsError {
617617
/// # Unix
618618
///
619619
/// - Returns the value of the 'HOME' environment variable if it is set
620-
/// (including to an empty string).
620+
/// (and not an empty string).
621621
/// - Otherwise, it tries to determine the home directory by invoking the `getpwuid_r` function
622622
/// using the UID of the current user. An empty home directory field returned from the
623623
/// `getpwuid_r` function is considered to be a valid value.

library/std/src/sys/pal/unix/os.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ pub fn temp_dir() -> PathBuf {
633633
}
634634

635635
pub fn home_dir() -> Option<PathBuf> {
636-
return crate::env::var_os("HOME").or_else(|| unsafe { fallback() }).map(PathBuf::from);
636+
return crate::env::var_os("HOME")
637+
.filter(|s| !s.is_empty())
638+
.or_else(|| unsafe { fallback() })
639+
.map(PathBuf::from);
637640

638641
#[cfg(any(
639642
target_os = "android",

0 commit comments

Comments
 (0)