mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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>
This commit is contained in:
parent
f18b226492
commit
d147e5e52c
3 changed files with 16 additions and 1 deletions
|
@ -16,7 +16,7 @@ def str_width(c: str) -> int:
|
||||||
|
|
||||||
|
|
||||||
def wlen(s: str) -> int:
|
def wlen(s: str) -> int:
|
||||||
if len(s) == 1:
|
if len(s) == 1 and s != '\x1a':
|
||||||
return str_width(s)
|
return str_width(s)
|
||||||
length = sum(str_width(i) for i in s)
|
length = sum(str_width(i) for i in s)
|
||||||
# remove lengths of any escape sequences
|
# remove lengths of any escape sequences
|
||||||
|
|
|
@ -329,6 +329,20 @@ class WindowsConsoleTests(TestCase):
|
||||||
def erase_in_line(self):
|
def erase_in_line(self):
|
||||||
return ERASE_IN_LINE.encode("utf8")
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix _pyrepl crash when entering a double CTRL-Z on an overflowing line.
|
Loading…
Add table
Add a link
Reference in a new issue