Skip to content

Commit 012966c

Browse files
committed
fix(_command_offset): restrict changes to COMP_* in the local scope
1 parent 39e250e commit 012966c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

bash_completion

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,13 @@ _command_offset()
22202220
# rewrite current completion context before invoking
22212221
# actual command completion
22222222

2223+
# make changes to COMP_* local. Note that bash-4.3..5.0 have a
2224+
# bug that `local -a arr=("${arr[@]}")` fails. We instead first
2225+
# assign the values of `COMP_WORDS` to another array `comp_words`.
2226+
local COMP_LINE=$COMP_LINE COMP_POINT=$COMP_POINT COMP_CWORD=$COMP_CWORD
2227+
local -a comp_words=("${COMP_WORDS[@]}")
2228+
local -a COMP_WORDS=("${comp_words[@]}")
2229+
22232230
# find new first word position, then
22242231
# rewrite COMP_LINE and adjust COMP_POINT
22252232
local word_offset=$1 i tail

test/t/unit/test_unit_command_offset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def join(words):
1212

1313
@pytest.mark.bashcomp(
1414
cmd=None,
15-
ignore_env=r"^[+-](COMP(_(WORDS|CWORD|LINE|POINT)|REPLY)|cur|cword|words)=",
15+
ignore_env=r"^[+-]COMPREPLY=",
1616
)
1717
class TestUnitCommandOffset:
1818
wordlist = sorted(["foo", "bar"])

0 commit comments

Comments
 (0)