Skip to content

Commit 0c70453

Browse files
miss-islingtoneendebakptblurb-it[bot]
authored
[3.13] gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (GH-126650) (#129154)
gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (GH-126650) (cherry picked from commit d147e5e) Co-authored-by: Pieter Eendebak <[email protected]> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent ffcef2d commit 0c70453

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Lib/_pyrepl/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def str_width(c: str) -> int:
1616

1717

1818
def wlen(s: str) -> int:
19-
if len(s) == 1:
19+
if len(s) == 1 and s != '\x1a':
2020
return str_width(s)
2121
length = sum(str_width(i) for i in s)
2222
# remove lengths of any escape sequences

Lib/test/test_pyrepl/test_windows_console.py

+14
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ def move_right(self, cols=1):
329329
def erase_in_line(self):
330330
return ERASE_IN_LINE.encode("utf8")
331331

332+
def test_multiline_ctrl_z(self):
333+
# see gh-126332
334+
code = "abcdefghi"
335+
336+
events = itertools.chain(
337+
code_to_events(code),
338+
[
339+
Event(evt="key", data='\x1a', raw=bytearray(b'\x1a')),
340+
Event(evt="key", data='\x1a', raw=bytearray(b'\x1a')),
341+
],
342+
)
343+
reader, _ = self.handle_events_narrow(events)
344+
self.assertEqual(reader.cxy, (2, 3))
345+
332346

333347
if __name__ == "__main__":
334348
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix _pyrepl crash when entering a double CTRL-Z on an overflowing line.

0 commit comments

Comments
 (0)