From 0d284bdc602a2506cc39b47af134608598d6883e Mon Sep 17 00:00:00 2001 From: Tom Tseng Date: Fri, 21 Jun 2024 17:34:28 -0700 Subject: [PATCH] autoenv_leave: Only match prefix on path boundaries Suppose we `cd` from `a/b` to `a/bz`. Expected behavior: Invoke `a/b/.env.leave. Actual behavior prior to this commit: No env-leave is invoked. The issue is that we are naively checking for string prefixes in `autoenv_leave` in order to determine whether one directory is an ancestor of another. This commit makes the checking slightly less naive. --- activate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activate.sh b/activate.sh index 85b3e26..9bf1c9e 100755 --- a/activate.sh +++ b/activate.sh @@ -295,7 +295,7 @@ autoenv_leave() { _files=$( command -v chdir >/dev/null 2>&1 && chdir "${from_dir}" || builtin cd "${from_dir}" _hadone='' - while [ "$PWD" != "" ] && [[ $to_dir != $PWD* ]]; do + while [ "$PWD" != "" ] && [ "$PWD" != "/" ] && [[ $to_dir/ != $PWD/* ]]; do _file="$PWD/${AUTOENV_ENV_LEAVE_FILENAME}" if [ -f "${_file}" ]; then if [ -z "${_hadone}" ]; then