Skip to content

Commit f45cd30

Browse files
committed
fix(_comp_compgen): adjust IFS for a quoting fix in bash 5.0
1 parent 7da1af1 commit f45cd30

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bash_completion

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ _comp_split()
416416
# completions.
417417
_comp_compgen()
418418
{
419-
local _append="" _var=COMPREPLY _cur=${cur-} IFS=$' \t\n'
419+
local _append="" _var=COMPREPLY _cur=${cur-} _ifs=$' \t\n'
420420
local -a _split_options=(-l)
421421

422422
local OPTIND=1 OPTARG="" OPTERR=0 _opt
@@ -430,8 +430,8 @@ _comp_compgen()
430430
fi
431431
_var=$OPTARG
432432
;;
433-
l) IFS=$'\n' ;;
434-
F) IFS=$OPTARG ;;
433+
l) _ifs=$'\n' ;;
434+
F) _ifs=$OPTARG ;;
435435
c) _cur=$OPTARG ;;
436436
R) _cur="" ;;
437437
*)
@@ -445,7 +445,14 @@ _comp_compgen()
445445
printf 'bash_completion: %s: unexpected number of arguments.\n' "$FUNCNAME" >&2
446446
printf 'usage: %s [-alR|-F SEP|-v ARR|-c CUR] -- ARGS...' "$FUNCNAME" >&2
447447
return 2
448-
elif [[ $* == *\$[0-9]* || $* == *\$\{[0-9]* ]]; then
448+
elif
449+
# Note: $* in the below checks would be affected by uncontrolled IFS in
450+
# bash >= 5.0, so we need to set IFS to the normal value. The behavior
451+
# in bash < 5.0, where unquoted $* in conditional command did not honor
452+
# IFS, was a bug.
453+
local IFS=$' \t\n'
454+
[[ $* == *\$[0-9]* || $* == *\$\{[0-9]* ]]
455+
then
449456
# Note: extglob *\$?(\{)[0-9]* can be extremely slow when the string
450457
# "${*:2:_nopt}" becomes longer, so we test \$[0-9] and \$\{[0-9]
451458
# separately.
@@ -454,7 +461,10 @@ _comp_compgen()
454461
fi
455462

456463
local _result
457-
_result=$(compgen "$@" ${_cur:+-- "$_cur"}) || {
464+
_result=$(
465+
IFS=$_ifs
466+
compgen "$@" ${_cur:+-- "$_cur"}
467+
) || {
458468
local _status=$?
459469
if [[ $_append ]]; then
460470
# make sure existence of variable

0 commit comments

Comments
 (0)