From c81857628b5258e740defab6c47ebe05ca713b7c Mon Sep 17 00:00:00 2001 From: hugel <2712504175@qq.com> Date: Tue, 26 Aug 2025 09:45:52 +0800 Subject: [PATCH] Fix regression of unwanted trailing colons --- ...gression_of_unwanted_trailing_colons.patch | 75 +++++++++++++++++++ bash-completion.spec | 8 +- 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 backport-fix_regression_of_unwanted_trailing_colons.patch diff --git a/backport-fix_regression_of_unwanted_trailing_colons.patch b/backport-fix_regression_of_unwanted_trailing_colons.patch new file mode 100644 index 0000000..cbc91d6 --- /dev/null +++ b/backport-fix_regression_of_unwanted_trailing_colons.patch @@ -0,0 +1,75 @@ +commit c2f83e0436208ef2bfa9c762bc28ff6374ba0c73 +Author: Koichi Murase +Date: Sun Mar 10 11:40:57 2024 +0900 + + fix(available_interfaces): fix regression of unwanted trailing colons + + This is a fix for regression introduced in commit b6035350 and + reported in GitHub #1129 [1]. The trailing colons of the generated + interface names were removed before, but not they are not removed. + + [1] https://github.com/scop/bash-completion/issues/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. + +diff --git a/bash_completion b/bash_completion +index e245cc55..82d73b53 100644 +--- a/bash_completion ++++ b/bash_completion +@@ -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. +diff --git a/test/t/unit/Makefile.am b/test/t/unit/Makefile.am +index 54722dea..a9bead09 100644 +--- a/test/t/unit/Makefile.am ++++ b/test/t/unit/Makefile.am +@@ -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 \ +diff --git a/test/t/unit/test_unit_compgen_available_interfaces.py b/test/t/unit/test_unit_compgen_available_interfaces.py +new file mode 100644 +index 00000000..5e931006 +--- /dev/null ++++ b/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() diff --git a/bash-completion.spec b/bash-completion.spec index 17e23b4..7bfe6da 100644 --- a/bash-completion.spec +++ b/bash-completion.spec @@ -3,7 +3,7 @@ Name: bash-completion Version: 2.16.0 -Release: 3 +Release: 4 Epoch: 1 Summary: Completion for bash command License: GPL-2.0-or-later @@ -14,6 +14,7 @@ Patch0: bash-completion-2.16.0-remove-python2.patch Patch6001: backport-refactor-secret-tool-deprecate-ours-in-favor-of-upstream.patch Patch6002: backport-fix-feh-fix-nounset-error.patch Patch6003: backport-fix-_umount-feh-sbopkg-check-diretory-name-for-_comp.patch +Patch6004: backport-fix_regression_of_unwanted_trailing_colons.patch BuildArch: noarch @@ -68,7 +69,10 @@ make -C completions check %doc CHANGELOG.md README.md doc/configuration.md CONTRIBUTING.md %changelog -*Tue May 27 2025 Linux_zhang - 1:2.16.0-3 +* Tue Aug 26 2025 hugel - 1:2.16.0-4 +- Fix regression of unwanted trailing colons + +* Tue May 27 2025 Linux_zhang - 1:2.16.0-3 - DESC:check diretory name for _comp_compgen -C * Tue Jan 28 2025 Funda Wang - 1:2.16.0-2 -- Gitee