diff --git a/ssh/terminal/terminal.go b/ssh/terminal/terminal.go index a0ddba3..66439cf 100644 --- a/ssh/terminal/terminal.go +++ b/ssh/terminal/terminal.go @@ -409,19 +409,22 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) { t.historyPending = string(t.line) } t.historyIndex++ - t.setLine([]rune(entry), len(entry)) + runes := []rune(entry) + t.setLine(runes, len(runes)) case keyDown: switch t.historyIndex { case -1: return case 0: - t.setLine([]rune(t.historyPending), len(t.historyPending)) + runes := []rune(t.historyPending) + t.setLine(runes, len(runes)) t.historyIndex-- default: entry, ok := t.history.NthPreviousEntry(t.historyIndex - 1) if ok { t.historyIndex-- - t.setLine([]rune(entry), len(entry)) + runes := []rune(entry) + t.setLine(runes, len(runes)) } } case keyEnter: diff --git a/ssh/terminal/terminal_test.go b/ssh/terminal/terminal_test.go index 6ea92d9..7fbf0e6 100644 --- a/ssh/terminal/terminal_test.go +++ b/ssh/terminal/terminal_test.go @@ -141,6 +141,16 @@ var keyPressTests = []struct { in: "Ξεσκεπάζω\r", line: "Ξεσκεπάζω", }, + { + in: "£\r\x1b[A\177\r", // non-ASCII char, enter, up, backspace. + line: "", + throwAwayLines: 1, + }, + { + in: "£\r££\x1b[A\x1b[B\177\r", // non-ASCII char, enter, 2x non-ASCII, up, down, backspace, enter. + line: "£", + throwAwayLines: 1, + }, } func TestKeyPresses(t *testing.T) {