]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (GH-126650...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 21 Jan 2025 21:04:41 +0000 (22:04 +0100)
committerGitHub <noreply@github.com>
Tue, 21 Jan 2025 21:04:41 +0000 (21:04 +0000)
gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (GH-126650)

(cherry picked from commit d147e5e52cdb90496ae5fe85b3263cdfa9407a28)

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Lib/_pyrepl/utils.py
Lib/test/test_pyrepl/test_windows_console.py
Misc/NEWS.d/next/Library/2024-11-10-19-45-01.gh-issue-126332.WCCKoH.rst [new file with mode: 0644]

index 0f36083b6ffa92cd95c75957f3d0734da852052d..4651717bd7e1219905309e0a09ceaf4c7cc1ad71 100644 (file)
@@ -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
index 4a3b2baf64a944377f55951ae6ea79965dc8d65f..07eaccd1124cd60e1d1d5bd8ea5fa256c225d153 100644 (file)
@@ -329,6 +329,20 @@ class WindowsConsoleTests(TestCase):
     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 (file)
index 0000000..9277797
--- /dev/null
@@ -0,0 +1 @@
+Fix _pyrepl crash when entering a double CTRL-Z on an overflowing line.