'main': Make logic more robust. No functional change.

Before this commit, if the value didn't begin with a dollar sign,
_zsh_highlight_main_highlighter__try_expand_parameter() would return 1
by accident.¹  Tweak the input validation to make this behaviour
explicit.  No functional change.

¹ Specifically, it would return 1 because ${parameter_name}'s value
would be the empty string and ${parameter_name_pattern} wouldn't match
that.
This commit is contained in:
Daniel Shahaf 2020-03-19 22:16:04 +00:00
parent 7678a8a227
commit 2aca4e2c02

View File

@ -439,9 +439,12 @@ _zsh_highlight_main_highlighter__try_expand_parameter()
local MATCH; integer MBEGIN MEND
local parameter_name
local -a words
if [[ $arg[1] == '$' ]] && [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then
if [[ $arg[1] != '$' ]]; then
return 1
fi
if [[ ${arg[2]} == '{' ]] && [[ ${arg[-1]} == '}' ]]; then
parameter_name=${${arg:2}%?}
elif [[ $arg[1] == '$' ]]; then
else
parameter_name=${arg:1}
fi
if [[ $res == none ]] && zmodload -e zsh/parameter &&