From 2aca4e2c02ae13753a0667b266d73afde7545f20 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Thu, 19 Mar 2020 22:16:04 +0000 Subject: [PATCH] 'main': Make logic more robust. No functional change. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- highlighters/main/main-highlighter.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index 5812af0..10abbb9 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -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 &&