Skip to content

[PATCH] Hangs when zsh is started under non-existent PWD #819

Open
@danielshahaf

Description

@danielshahaf

To reproduce:

$ cd "$(mktemp -d)"
$ rm -rf -- "$(pwd)"
$ zsh -f
% source /path/to/zsh-syntax-highlighting.zsh
% [try to type]

When I do that, the typing doesn't echo; only the first letter shows, sometimes immediately, sometimes only after a ^C.

zsh-5.8-387-gdf899d3 (3½ months old), z-sy-h current master (dffe304), Linux.

The only use of $PWD in our code, other than tests, is here:

# Check if this is a blacklisted path
if [[ $expanded_path[1] == / ]]; then
tmp_path=$expanded_path
else
tmp_path=$PWD/$expanded_path
fi
tmp_path=$tmp_path:a
while [[ $tmp_path != / ]]; do
[[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1
tmp_path=$tmp_path:h
done

That looks like an infinite loop.

Proposed patch:

diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh
index b251a3c..8da01fd 100644
--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -1239,7 +1239,11 @@ _zsh_highlight_main_highlighter_check_path()
   fi
   tmp_path=$tmp_path:a
 
-  while [[ $tmp_path != / ]]; do
+  # Check whether $tmp_path is blacklisted.
+  #
+  # The loop will terminate when $tmp_path is the root directory (equal to "/")
+  # or starts with a dot (which can happen if $PWD doesn't exist; issue #819).
+  while [[ ${tmp_path:0:2} = /? ]]; do
     [[ -n ${(M)ZSH_HIGHLIGHT_DIRS_BLACKLIST:#$tmp_path} ]] && return 1
     tmp_path=$tmp_path:h
   done

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions