Skip to content

Commit 64875fd

Browse files
Rémi Laurentakinomyoga
andcommitted
fix(_comp__included_ssh_config_files): ignore comments in "Include"
Co-authored-by: Koichi Murase <[email protected]>
1 parent 3c2cac0 commit 64875fd

File tree

5 files changed

+8
-1
lines changed

5 files changed

+8
-1
lines changed

bash_completion

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,8 @@ _comp__included_ssh_config_files()
25422542
# https://github.com/openssh/openssh-portable/blob/5ec5504f1d328d5bfa64280cd617c3efec4f78f3/readconf.c#L2240
25432543
local max_depth=16
25442544
while ((${#included[@]} > 0 && depth++ < max_depth)); do
2545-
_comp_split include_files "$(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' "${included[@]}")" || return
2545+
_comp_split include_files "$(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]*\([^#]*\).*$/\1/p' "${included[@]}")" || return
2546+
25462547
included=()
25472548
for i in "${include_files[@]}"; do
25482549
if [[ $i != [~/]* ]]; then
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Host with_comment
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Host this_file_should_not_be_included

test/fixtures/_known_hosts/config_include

Lines changed: 2 additions & 0 deletions
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 # inside_comment this should be ignored

test/t/unit/test_unit_compgen_known_hosts.py

Lines changed: 2 additions & 0 deletions
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)