Skip to content

Commit

Permalink
Merge pull request paramiko#656 from 56quarters/bugfix/499
Browse files Browse the repository at this point in the history
Update SSHConfig.parse to strip leading and trailing whitespace
  • Loading branch information
bitprophet committed Jan 19, 2016
2 parents d0d0c32 + 0c93fa9 commit 10bb177
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def parse(self, file_obj):
"""
host = {"host": ['*'], "config": {}}
for line in file_obj:
line = line.rstrip('\r\n').lstrip()
# Strip any leading or trailing whitespace from the line.
# See https://github.com/paramiko/paramiko/issues/499 for more info.
line = line.strip()
if not line or line.startswith('#'):
continue
if '=' in line:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from tests.util import ParamikoTest

# Note some lines in this configuration have trailing spaces on purpose
test_config_file = """\
Host *
User robey
Expand Down Expand Up @@ -105,7 +106,7 @@ def test_2_parse_config(self):
self.assertEqual(config._config,
[{'host': ['*'], 'config': {}}, {'host': ['*'], 'config': {'identityfile': ['~/.ssh/id_rsa'], 'user': 'robey'}},
{'host': ['*.example.com'], 'config': {'user': 'bjork', 'port': '3333'}},
{'host': ['*'], 'config': {'crazy': 'something dumb '}},
{'host': ['*'], 'config': {'crazy': 'something dumb'}},
{'host': ['spoo.example.com'], 'config': {'crazy': 'something else'}}])

def test_3_host_config(self):
Expand All @@ -114,14 +115,14 @@ def test_3_host_config(self):
config = paramiko.util.parse_ssh_config(f)

for host, values in {
'irc.danger.com': {'crazy': 'something dumb ',
'irc.danger.com': {'crazy': 'something dumb',
'hostname': 'irc.danger.com',
'user': 'robey'},
'irc.example.com': {'crazy': 'something dumb ',
'irc.example.com': {'crazy': 'something dumb',
'hostname': 'irc.example.com',
'user': 'robey',
'port': '3333'},
'spoo.example.com': {'crazy': 'something dumb ',
'spoo.example.com': {'crazy': 'something dumb',
'hostname': 'spoo.example.com',
'user': 'robey',
'port': '3333'}
Expand Down

0 comments on commit 10bb177

Please sign in to comment.