Skip to content

Commit c2f83e0

Browse files
akinomyogabash-completion machine user
authored andcommitted
fix(available_interfaces): fix regression of unwanted trailing colons
This is a fix for regression introduced in commit b603535 and reported in GitHub #1129 [1]. The trailing colons of the generated interface names were removed before, but not they are not removed. [1] #1129 In addition, generated words can have the form `veth0@veth1`, where we want only the first part `veth0` not containing any punctuation characters. In this patch, we remove any [[:punct:]] and all the later characters in the generated words.
1 parent fdd8048 commit c2f83e0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ _comp_compgen_available_interfaces()
17371737
fi
17381738
} 2>/dev/null | _comp_awk \
17391739
'/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }')" &&
1740-
_comp_compgen -U generated set "${generated[@]}"
1740+
_comp_compgen -U generated set "${generated[@]%%[[:punct:]]*}"
17411741
}
17421742

17431743
# Echo number of CPUs, falling back to 1 on failure.

test/t/unit/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ EXTRA_DIST = \
22
test_unit_abspath.py \
33
test_unit_command_offset.py \
44
test_unit_compgen.py \
5+
test_unit_compgen_available_interfaces.py \
56
test_unit_compgen_commands.py \
67
test_unit_count_args.py \
78
test_unit_delimited.py \
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec
4+
5+
6+
@pytest.mark.bashcomp(cmd=None)
7+
class TestUtilCompgenAvailableInterfaces:
8+
@pytest.fixture
9+
def functions(self, bash):
10+
assert_bash_exec(
11+
bash,
12+
"_comp__test_dump() { ((${#arr[@]})) && printf '<%s>' \"${arr[@]}\"; echo; }",
13+
)
14+
assert_bash_exec(
15+
bash,
16+
'_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }',
17+
)
18+
19+
def test_1_trailing_colons(self, bash, functions):
20+
output = assert_bash_exec(
21+
bash,
22+
"_comp__test_compgen available_interfaces",
23+
want_output=True,
24+
)
25+
assert ":" not in output.strip()

0 commit comments

Comments
 (0)