Skip to content

Commit 216734b

Browse files
yedayakakinomyoga
authored andcommitted
fix(ip): Quote network namespace names
Network namespaces can have spaces in them, which lead to incorrect completions in that case. Quote them by using printf %q on all namespace names. Co-authored-by: Koichi Murase <[email protected]>
1 parent 21f7e32 commit 216734b

File tree

1 file changed

+11
-2
lines changed
  • completions

1 file changed

+11
-2
lines changed

completions/ip

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ _comp_cmd_ip__iproute2_etc()
88

99
_comp_cmd_ip__netns()
1010
{
11-
_comp_compgen_split -- "$(
11+
local unquoted
12+
_comp_split -l unquoted "$(
1213
{
1314
${1-ip} -c=never netns list 2>/dev/null || ${1-ip} netns list
14-
} | _comp_awk '{print $1}'
15+
} | command sed -e 's/ (.*//'
1516
)"
17+
# namespace names can have spaces, so we quote all of them if needed
18+
local ns quoted=()
19+
for ns in "${unquoted[@]}"; do
20+
local namespace
21+
printf -v namespace '%q' "$ns"
22+
quoted+=("$namespace")
23+
done
24+
((${#quoted[@]})) && _comp_compgen -- -W '"${quoted[@]}"'
1625
}
1726

1827
_comp_cmd_ip__link_types()

0 commit comments

Comments
 (0)