Skip to content

Commit

Permalink
fix(available_interfaces): fix regression of unwanted trailing colons
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akinomyoga authored and bash-completion committed Mar 10, 2024
1 parent fdd8048 commit c2f83e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bash_completion
Expand Up @@ -1737,7 +1737,7 @@ _comp_compgen_available_interfaces()
fi
} 2>/dev/null | _comp_awk \
'/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }')" &&
_comp_compgen -U generated set "${generated[@]}"
_comp_compgen -U generated set "${generated[@]%%[[:punct:]]*}"
}

# Echo number of CPUs, falling back to 1 on failure.
Expand Down
1 change: 1 addition & 0 deletions test/t/unit/Makefile.am
Expand Up @@ -2,6 +2,7 @@ EXTRA_DIST = \
test_unit_abspath.py \
test_unit_command_offset.py \
test_unit_compgen.py \
test_unit_compgen_available_interfaces.py \
test_unit_compgen_commands.py \
test_unit_count_args.py \
test_unit_delimited.py \
Expand Down
25 changes: 25 additions & 0 deletions test/t/unit/test_unit_compgen_available_interfaces.py
@@ -0,0 +1,25 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
class TestUtilCompgenAvailableInterfaces:
@pytest.fixture
def functions(self, bash):
assert_bash_exec(
bash,
"_comp__test_dump() { ((${#arr[@]})) && printf '<%s>' \"${arr[@]}\"; echo; }",
)
assert_bash_exec(
bash,
'_comp__test_compgen() { local -a arr=(00); _comp_compgen -v arr "$@"; _comp__test_dump; }',
)

def test_1_trailing_colons(self, bash, functions):
output = assert_bash_exec(
bash,
"_comp__test_compgen available_interfaces",
want_output=True,
)
assert ":" not in output.strip()

0 comments on commit c2f83e0

Please sign in to comment.