Skip to content

Commit

Permalink
Fix pyrepl crash for double ctrl-z in line overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Nov 10, 2024
1 parent 0f6bb28 commit 7dfa24e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/_pyrepl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def str_width(c: str) -> int:


def wlen(s: str) -> int:
if len(s) == 1:
if len(s) == 1 and s != '\x1a':
return str_width(s)
length = sum(str_width(i) for i in s)
# remove lengths of any escape sequences
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_pyrepl/test_windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ def move_right(self, cols=1):
def erase_in_line(self):
return ERASE_IN_LINE.encode("utf8")

def test_multiline_ctrl_z(self):
# see gh-126332
code = "abcdefghi"

events = itertools.chain(
code_to_events(code),
[
Event(evt="key", data='\x1a', raw=bytearray(b'\x1a')),
Event(evt="key", data='\x1a', raw=bytearray(b'\x1a')),
],
)
reader, _ = self.handle_events_narrow(events)
self.assertEqual(reader.cxy, (2, 3))


if __name__ == "__main__":
unittest.main()

0 comments on commit 7dfa24e

Please sign in to comment.