Skip to content

Commit 663255d

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

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

bash_completion

Lines changed: 2 additions & 1 deletion
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Host with_comment

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 # this should be ignored

test/t/unit/test_unit_known_hosts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from itertools import chain
22

33
import pytest
4-
54
from conftest import assert_bash_exec, bash_env_saved
65

76

@@ -127,6 +126,8 @@ def test_included_configs(self, bash, hosts):
127126
expected.extend("asterisk_1 asterisk_2".split())
128127
# fixtures/_known_hosts/.ssh/config_question_mark
129128
expected.append("question_mark")
129+
# fixtures/_known_hosts/.ssh/config_comment
130+
expected.append("with_comment")
130131

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

0 commit comments

Comments
 (0)