From 2a30d4fb5aeb8489c4c70eb694c5f6d5827dfc1d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 2 Apr 2020 23:32:28 +0000 Subject: [PATCH] 'main': Fix an infinite loop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On the test case, the behaviour was as follows: +highlighters/main/main-highlighter.zsh:733> _zsh_highlight_main_highlighter__try_expand_parameter '$1' +highlighters/main/main-highlighter.zsh:432> local arg='$1' +highlighters/main/main-highlighter.zsh:433> unset reply +highlighters/main/main-highlighter.zsh:439> local -a match mbegin mend +highlighters/main/main-highlighter.zsh:440> local MATCH +highlighters/main/main-highlighter.zsh:440> integer MBEGIN MEND +highlighters/main/main-highlighter.zsh:441> local parameter_name +highlighters/main/main-highlighter.zsh:442> local -a words +highlighters/main/main-highlighter.zsh:443> [[ '$' != \$ ]] +highlighters/main/main-highlighter.zsh:446> [[ 1 == { ]] +highlighters/main/main-highlighter.zsh:449> parameter_name=1 +highlighters/main/main-highlighter.zsh:451> [[ none == none ]] +highlighters/main/main-highlighter.zsh:451> zmodload -e zsh/parameter +highlighters/main/main-highlighter.zsh:452> [[ ${parameter_name} -regex-match ^${~parameter_name_pattern}$ ]] +highlighters/main/main-highlighter.zsh:453> [[ '' != *special* ]] +highlighters/main/main-highlighter.zsh:456> case array-special (*array*|*assoc*) +highlighters/main/main-highlighter.zsh:458> words=( '$1' ) +highlighters/main/main-highlighter.zsh:469> reply=( '$1' ) There are two problems here: - In terms of _zsh_highlight_main_highlighter__try_expand_parameter's pre- and postconditions, the expansion of the word «$1» (line 733) included that same word (line 469). That happened because word-to-be-expanded is passed to _zsh_highlight_main_highlighter__try_expand_parameter as its first positional parameter, and in this case the word happened to be «$1». - Furthermore, the exclusion of special parameters (line 453) false negatived. That happened because $parameter_name_pattern explicitly allows positional parameters, but ${parameters[(e)1]} expands to nothing. This will be fixed in the next commit. Not a regression from 0.7.1. --- highlighters/main/main-highlighter.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 6c9bc25..a190a5f 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -730,7 +730,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi # Expand parameters. - if _zsh_highlight_main_highlighter__try_expand_parameter "$arg"; then + if (( ! in_param )) && _zsh_highlight_main_highlighter__try_expand_parameter "$arg"; then # That's not entirely correct --- if the parameter's value happens to be a reserved # word, the parameter expansion will be highlighted as a reserved word --- but that # incorrectness is outweighed by the usability improvement of permitting the use of