Skip to content

Commit ffc2178

Browse files
author
Rémi Laurent
committed
fix(_comp__included_ssh_config_files): ignore comments
1 parent 3039122 commit ffc2178

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

bash_completion

+2-1
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,8 @@ _comp__included_ssh_config_files()
24472447
# https://github.com/openssh/openssh-portable/blob/5ec5504f1d328d5bfa64280cd617c3efec4f78f3/readconf.c#L2240
24482448
local max_depth=16
24492449
while ((${#included[@]} > 0 && depth++ < max_depth)); do
2450-
_comp_split include_files "$(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' "${included[@]}")" || return
2450+
_comp_split include_files "$(command sed -n -e 's/[[:blank:]]*#.*//' -e 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]*\(..*\)/\1/p' "${included[@]}")" || return
2451+
24512452
included=()
24522453
for i in "${include_files[@]}"; do
24532454
if [[ $i != [~/]* ]]; then
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Host with_comment

test/fixtures/_known_hosts/config_include

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ Include config_relative_path
77
Include config_asterisk* config_?uestion_mark
88
# Include a directory name. This is a misconfiguration, but ssh ignores it without errors.
99
Include ../../_known_hosts
10+
# Include with extra comment
11+
Include config_comment # this should be ignored

test/t/unit/test_unit_known_hosts.py

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def test_included_configs(self, bash, hosts):
127127
expected.extend("asterisk_1 asterisk_2".split())
128128
# fixtures/_known_hosts/.ssh/config_question_mark
129129
expected.append("question_mark")
130+
# fixtures/_known_hosts/.ssh/config_comment
131+
expected.append("with_comment")
130132

131133
with bash_env_saved(bash) as bash_env:
132134
bash_env.write_variable("HOME", "%s/_known_hosts" % bash.cwd)

0 commit comments

Comments
 (0)