Skip to content

Commit 3cf004c

Browse files
committed
fix(_comp_compgen): prevent IFS from affecting -- "$cur"
The IFS separators specified by the options `-s SEP` or `-l` option is intended to take effect in evaluating `compgen`, such as the word splitting in `-W text`. However, if we set IFS in a separate command from `compgen`, the arguments specified to `compgen` would also be unexpectedly affected. Here, ${_cur:+-- "$_cur"} is intended to be expanded to two words if `_cur` is non-empty. However, when the separators do not contain a whitespace, it unexpectedly results in a single word. IFS can be specified as a temporary environment of the `compgen` command so that it does not affect the arguments of `compgen`.
1 parent 4e51a79 commit 3cf004c

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

bash_completion

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ _comp_compgen()
533533

534534
local _result
535535
_result=$(
536-
IFS=$_ifs
537-
compgen "$@" ${_cur:+-- "$_cur"}
536+
IFS=$_ifs compgen "$@" ${_cur:+-- "$_cur"}
538537
) || {
539538
local _status=$?
540539
if [[ $_append ]]; then

0 commit comments

Comments
 (0)