fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

IndexError with ANSI codes #75

Open sergehauri opened 2 years ago

sergehauri commented 2 years ago

In the expect method, when self.current_output is still empty and current_buffer_decodedis empty because the current_buffer only contains an ANSI escape code (and strip_ansi is True), the following exception is raised:

  File "/srv/www/rantools/venvs/infenv3/lib/python3.6/site-packages/paramiko_expect.py", line 191, in expect
    current_buffer_output_decoded = '\n' + self.current_output.splitlines()[-1]
IndexError: list index out of range

I refrained from setting up a reproducible example because I think the error is easy enough to understand from the code alone. Easiest would probably be to only change current_buffer_output_decoded if self.current_output isn't empty.