Skip to content

gh-126332: Fix pyrepl crash for double ctrl-z in line overflow #126650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix _pyrepl crash when entering a double CTRL-Z on an overflowing line.
Loading