Open
Description
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:
zsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
Lines 1234 to 1245 in dffe304
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