https://github.com/python/cpython/commit/d147e5e52cdb90496ae5fe85b3263cdfa9407a28
commit: d147e5e52cdb90496ae5fe85b3263cdfa9407a28
branch: main
author: Pieter Eendebak <[email protected]>
committer: pablogsal <[email protected]>
date: 2025-01-21T20:14:10Z
summary:
gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (#126650)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2024-11-10-19-45-01.gh-issue-126332.WCCKoH.rst
M Lib/_pyrepl/utils.py
M Lib/test/test_pyrepl/test_windows_console.py
diff --git a/Lib/_pyrepl/utils.py b/Lib/_pyrepl/utils.py
index 0f36083b6ffa92..4651717bd7e121 100644
--- a/Lib/_pyrepl/utils.py
+++ b/Lib/_pyrepl/utils.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_windows_console.py
b/Lib/test/test_pyrepl/test_windows_console.py
index 4a3b2baf64a944..07eaccd1124cd6 100644
--- a/Lib/test/test_pyrepl/test_windows_console.py
+++ b/Lib/test/test_pyrepl/test_windows_console.py
@@ -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()
diff --git
a/Misc/NEWS.d/next/Library/2024-11-10-19-45-01.gh-issue-126332.WCCKoH.rst
b/Misc/NEWS.d/next/Library/2024-11-10-19-45-01.gh-issue-126332.WCCKoH.rst
new file mode 100644
index 00000000000000..9277797ddc745e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-10-19-45-01.gh-issue-126332.WCCKoH.rst
@@ -0,0 +1 @@
+Fix _pyrepl crash when entering a double CTRL-Z on an overflowing line.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]