Skip to content
Myr

[shell] Avoid side-effects during eval (#3459)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Take two. * Avoid eval if the prefix contains `:=` * This is not to evaluate variable assignment. e.g. ${FOO:=BAR} * [zsh] Prevent `>(...)` form * Suppress error message from prefix evaluation * Stop completion when prefix evaluation failed Thanks to @calestyo

authored by Junegunn Choi · committed by Junegunn Choi · parent e833823 · Browse files · 2 files+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−6 removed

  • other:+6 added−6 removed

2 files+6 added−6 removed

modified:shell/completion.bash+3 added-3 removed
168 unmodified lines
169 cmd="${cmd//[^A-Za-z0-9_=]/_}"170 COMPREPLY=()171 trigger=${FZF_COMPLETION_TRIGGER-'**'}172 cur="${COMP_WORDS[COMP_CWORD]}"173 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *'<('* ]] && [[ $cur != *'`'* ]]; then173 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then174 base=${cur:0:${#cur}-${#trigger}}175 eval "base=$base"175 eval "base=$base" 2> /dev/null || return176177 dir=178 [[ $base = *"/"* ]] && dir="$base"179 while true; do
54 unmodified lines
234235 cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"236 trigger=${FZF_COMPLETION_TRIGGER-'**'}237 cur="${COMP_WORDS[COMP_CWORD]}"238 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *'<('* ]] && [[ $cur != *'`'* ]]; then238 if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then239 cur=${cur:0:${#cur}-${#trigger}}240241 selected=$(FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $str_arg" __fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | tr '\n' ' ')242 selected=${selected% } # Strip trailing space not to repeat "-o nospace"
163 unmodified lines
modified:shell/completion.zsh+3 added-3 removed
135 unmodified lines
136 suffix=$5137 tail=$6138139 setopt localoptions nonomatch140 if [[ $base = *'$('* ]] || [[ $base = *'<('* ]] || [[ $base = *'`'* ]]; then140 if [[ $base = *'$('* ]] || [[ $base = *'<('* ]] || [[ $base = *'>('* ]] || [[ $base = *':='* ]] || [[ $base = *'`'* ]]; then141 return142 fi143 eval "base=$base"143 eval "base=$base" 2> /dev/null || return144 [[ $base = *"/"* ]] && dir="$base"145 while [ 1 ]; do146 if [[ -z "$dir" || -d ${dir} ]]; then147 leftover=${base/#"$dir"}
158 unmodified lines
306 if [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then307 d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir})308309 [ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}310 if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'`'* ]]; then310 if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'>('* ]] || [[ $prefix = *':='* ]] || [[ $prefix = *'`'* ]]; then311 return312 fi313 [ -n "${tokens[-1]}" ] && lbuf=${lbuf:0:-${#tokens[-1]}}314
28 unmodified lines