Skip to content

Commit

Permalink
fix(_comp__included_ssh_config_files): ignore comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Laurent committed Jun 4, 2024
1 parent 3039122 commit ffc2178
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
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 # this should be ignored
2 changes: 2 additions & 0 deletions test/t/unit/test_unit_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

0 comments on commit ffc2178

Please sign in to comment.