Skip to content

Commit

Permalink
Add code 'ESC[c' into method 'strip_ansi_escape_codes'
Browse files Browse the repository at this point in the history
Some 'MikroTik' devices add ANSI escape codes 'ESC[c' to the end
of the output when in 'safe-mode'
  • Loading branch information
max-dw-i committed Jul 8, 2024
1 parent 235217b commit 3850d19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion netmiko/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,8 @@ def strip_ansi_escape_codes(self, string_buffer: str) -> str:
ESC[6n Get cursor position
ESC[1D Move cursor position leftward by x characters (1 in this case)
ESC[9999B Move cursor down N-lines (very large value is attempt to move to the
very bottom of the screen).
very bottom of the screen)
ESC[c Unknown code (added, for example, by MikroTik in 'Safe-Mode').
HP ProCurve and Cisco SG300 require this (possible others).
Expand Down Expand Up @@ -2398,6 +2399,7 @@ def strip_ansi_escape_codes(self, string_buffer: str) -> str:
code_cursor_down = chr(27) + r"\[\d*B"
code_wrap_around = chr(27) + r"\[\?7h"
code_bracketed_paste_mode = chr(27) + r"\[\?2004h"
code_unknown_0 = chr(27) + r"\[c"

code_set = [
code_position_cursor,
Expand Down Expand Up @@ -2428,6 +2430,7 @@ def strip_ansi_escape_codes(self, string_buffer: str) -> str:
code_cursor_forward,
code_wrap_around,
code_bracketed_paste_mode,
code_unknown_0,
]

output = string_buffer
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def test_strip_ansi_codes():
"\x1b[J", # code_erase_display
"\x1b[0m", # code_attrs_off
"\x1b[7m", # code_reverse
"\x1b[c", # code_unknown_0
]
for ansi_code in ansi_codes_to_strip:
assert connection.strip_ansi_escape_codes(ansi_code) == ""
Expand Down

0 comments on commit 3850d19

Please sign in to comment.