bash-completion: fix variable leaks of "IFS" and "word"

Signed-off-by: Koichi Murase <myoga.murase@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Koichi Murase 2021-11-14 15:06:40 +09:00 committed by Michal Privoznik
parent 00c0ba5de3
commit 097296c30b

View File

@ -21,7 +21,7 @@ _@command@_complete()
# See what URI is user trying to connect to and if they are # See what URI is user trying to connect to and if they are
# connecting RO. Honour that. # connecting RO. Honour that.
while [ $c -le $COMP_CWORD ]; do while [ $c -le $COMP_CWORD ]; do
word="${COMP_WORDS[c]}" local word="${COMP_WORDS[c]}"
case "$word" in case "$word" in
-r|--readonly) RO=1 ;; -r|--readonly) RO=1 ;;
-c|--connect) c=$((++c)); URI=${COMP_WORDS[c]} ;; -c|--connect) c=$((++c)); URI=${COMP_WORDS[c]} ;;
@ -56,7 +56,8 @@ _@command@_complete()
# the name of the command whose arguments are being # the name of the command whose arguments are being
# completed. # completed.
# Therefore, we might just run $1. # Therefore, we might just run $1.
IFS=$'\n' A=($($1 ${CMDLINE[@]} complete -- "${INPUT[@]}" 2>/dev/null)) local IFS=$'\n'
A=($($1 ${CMDLINE[@]} complete -- "${INPUT[@]}" 2>/dev/null))
COMPREPLY=($(compgen -W "${A[*]%--}" -- ${cur})) COMPREPLY=($(compgen -W "${A[*]%--}" -- ${cur}))
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"