From a2f507f1c855cdcf5d15435162060f2b45bbdc42 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 13 Aug 2017 14:57:31 -0700 Subject: [PATCH] Revert "remove more ENV_NULL references" This reverts commit 591449aba72f5f6a8fa646f57704ece4428eccb4. It was meant for the major branch. --- src/builtin_set.cpp | 2 ++ src/expand.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 8672e6fcc..1d1af95a6 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -293,6 +293,8 @@ static int my_env_set(const wchar_t *cmd, const wchar_t *key, const wcstring_lis if (retval != STATUS_CMD_OK) return retval; } + // We don't check `val->empty()` because an array var with a single empty string will be + // "empty". A truly empty array var is set to the special value `ENV_NULL`. auto val = list_to_array_val(list); retval = env_set(key, val->c_str(), scope | ENV_USER); switch (retval) { diff --git a/src/expand.cpp b/src/expand.cpp index 2bcc6ec18..4a34ba4a2 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -1172,8 +1172,16 @@ static void expand_home_directory(wcstring &input) { if (username.empty()) { // Current users home directory. home = env_get(L"HOME"); + // If home is either missing or empty, + // treat it like an empty list. + // $HOME is defined to be a _path_, + // and those cannot be empty. + // + // We do not expand a string-empty var differently, + // because that results in bogus paths + // - ~/foo turns into /foo. if (home.missing_or_empty()) { - input.clear(); + input = ENV_NULL; return; } tail_idx = 1;