diff --git a/bash_completion b/bash_completion index cc9caa2425e..bca6801c514 100644 --- a/bash_completion +++ b/bash_completion @@ -2447,7 +2447,8 @@ _comp__included_ssh_config_files() # https://github.com/openssh/openssh-portable/blob/5ec5504f1d328d5bfa64280cd617c3efec4f78f3/readconf.c#L2240 local max_depth=16 while ((${#included[@]} > 0 && depth++ < max_depth)); do - _comp_split include_files "$(command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' "${included[@]}")" || return + _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 + included=() for i in "${include_files[@]}"; do if [[ $i != [~/]* ]]; then diff --git a/test/fixtures/_known_hosts/.ssh/config_comment b/test/fixtures/_known_hosts/.ssh/config_comment new file mode 100644 index 00000000000..0211d3598cf --- /dev/null +++ b/test/fixtures/_known_hosts/.ssh/config_comment @@ -0,0 +1 @@ +Host with_comment diff --git a/test/fixtures/_known_hosts/config_include b/test/fixtures/_known_hosts/config_include index d68b0d81597..298f3e95e28 100644 --- a/test/fixtures/_known_hosts/config_include +++ b/test/fixtures/_known_hosts/config_include @@ -7,3 +7,5 @@ Include config_relative_path Include config_asterisk* config_?uestion_mark # Include a directory name. This is a misconfiguration, but ssh ignores it without errors. Include ../../_known_hosts +# Include with extra comment +Include config_comment # this should be ignored diff --git a/test/t/unit/test_unit_known_hosts.py b/test/t/unit/test_unit_known_hosts.py index b0f715b3679..4652e787548 100644 --- a/test/t/unit/test_unit_known_hosts.py +++ b/test/t/unit/test_unit_known_hosts.py @@ -127,6 +127,8 @@ def test_included_configs(self, bash, hosts): expected.extend("asterisk_1 asterisk_2".split()) # fixtures/_known_hosts/.ssh/config_question_mark expected.append("question_mark") + # fixtures/_known_hosts/.ssh/config_comment + expected.append("with_comment") with bash_env_saved(bash) as bash_env: bash_env.write_variable("HOME", "%s/_known_hosts" % bash.cwd)