Skip to content

Ignore comments in ssh_config Include parsing #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2542,7 +2542,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 -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]*\([^#]*\).*$/\1/p' "${included[@]}")" || return

included=()
for i in "${include_files[@]}"; do
if [[ $i != [~/]* ]]; then
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/_known_hosts/.ssh/config_comment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Host with_comment
1 change: 1 addition & 0 deletions test/fixtures/_known_hosts/.ssh/inside_comment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Host this_file_should_not_be_included
2 changes: 2 additions & 0 deletions test/fixtures/_known_hosts/config_include
Original file line number Diff line number Diff line change
Expand Up @@ -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 # inside_comment this should be ignored
2 changes: 2 additions & 0 deletions test/t/unit/test_unit_compgen_known_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading