]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124927: Fix conversion issue between coordinates and position in REPL (#125001)
authorFeH2 <i@feh2.im>
Mon, 10 Mar 2025 21:54:49 +0000 (05:54 +0800)
committerGitHub <noreply@github.com>
Mon, 10 Mar 2025 21:54:49 +0000 (21:54 +0000)
Lib/_pyrepl/reader.py
Lib/test/test_pyrepl/test_reader.py
Misc/ACKS
Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst [new file with mode: 0644]

index 1252847e02b2eacab4caed35b9af53efe6d9d594..4795c51296a50077fc71a102a6f023763f1e36c1 100644 (file)
@@ -62,7 +62,7 @@ def disp_str(buffer: str) -> tuple[str, list[int]]:
         elif unicodedata.category(c).startswith("C"):
             c = r"\u%04x" % ord(c)
             s.append(c)
-            b.extend([0] * (len(c) - 1))
+            b.append(len(c))
         else:
             s.append(c)
             b.append(str_width(c))
@@ -577,6 +577,7 @@ class Reader:
         cur_x = self.screeninfo[i][0]
         while cur_x < x:
             if self.screeninfo[i][1][j] == 0:
+                j += 1  # prevent potential future infinite loop
                 continue
             cur_x += self.screeninfo[i][1][j]
             j += 1
index f3b243d3c279e5c20c00188a1295e0dc09ed8495..468c0c5e68d165cdc4748a5198656fc8f51355b1 100644 (file)
@@ -319,3 +319,11 @@ class TestReader(TestCase):
         # Simulate a resize to 0 columns
         reader.screeninfo = []
         self.assertEqual(reader.pos2xy(), (0, 0))
+
+    def test_setpos_from_xy_for_non_printing_char(self):
+        code = "# non \u200c printing character"
+        events = code_to_events(code)
+
+        reader, _ = handle_all_events(events)
+        reader.setpos_from_xy(8, 0)
+        self.assertEqual(reader.pos, 7)
index d110002ffeb86ca8d010dbd540d6d0ef7d611d4d..da528f8b4ca3a72a151f93f90e192d6f8ffecc3b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -279,6 +279,7 @@ Laurent De Buyst
 Zach Byrne
 Vedran Čačić
 Nicolas Cadou
+Zhikai Cai
 Jp Calderone
 Ben Caller
 Arnaud Calmettes
diff --git a/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst
new file mode 100644 (file)
index 0000000..1fc485c
--- /dev/null
@@ -0,0 +1 @@
+Non-printing characters are now properly handled in the new REPL.