[3.13] gh-126332: Fix pyrepl crash for double ctrl-z in line overflow (GH-126650) (#129154)
https://github.com/python/cpython/commit/0c7045378f593e588576bcc7fb1eabfe153... commit: 0c7045378f593e588576bcc7fb1eabfe15398aeb branch: 3.13 author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> committer: pablogsal <Pablogsal@gmail.com> date: 2025-01-21T21:04:41Z summary: [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 d147e5e52cdb90496ae5fe85b3263cdfa9407a28) Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> 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.
participants (1)
-
pablogsal