From e745996b2d24b9234f896bdc2f3320e49287dcd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20G=C3=B3mez=20Mac=C3=ADas?= Date: Sat, 13 Jul 2024 12:44:18 +0200 Subject: gh-121609: Fix pasting of characters containing unicode character joiner (#121667) --- Lib/_pyrepl/reader.py | 1 - Lib/test/test_pyrepl/test_reader.py | 6 ++++++ .../2024-07-13-09-51-44.gh-issue-121609.jWsE5t.rst | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-07-13-09-51-44.gh-issue-121609.jWsE5t.rst diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 63ae661..1622d30 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -58,7 +58,6 @@ 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.append(str_width(c)) b.extend([0] * (len(c) - 1)) else: s.append(c) diff --git a/Lib/test/test_pyrepl/test_reader.py b/Lib/test/test_pyrepl/test_reader.py index 986bc36..e82c3ca 100644 --- a/Lib/test/test_pyrepl/test_reader.py +++ b/Lib/test/test_pyrepl/test_reader.py @@ -88,6 +88,12 @@ class TestReader(TestCase): reader.setpos_from_xy(0, 0) self.assertEqual(reader.pos, 0) + def test_control_characters(self): + code = 'flag = "🏳️‍🌈"' + events = code_to_events(code) + reader, _ = handle_all_events(events) + self.assert_screen_equals(reader, 'flag = "🏳️\\u200d🌈"') + def test_setpos_from_xy_multiple_lines(self): # fmt: off code = ( diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-07-13-09-51-44.gh-issue-121609.jWsE5t.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-07-13-09-51-44.gh-issue-121609.jWsE5t.rst new file mode 100644 index 0000000..72b5c07 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-07-13-09-51-44.gh-issue-121609.jWsE5t.rst @@ -0,0 +1 @@ +Fix pasting of characters containing unicode character joiners in the new REPL. Patch by Marta Gomez Macias -- cgit v0.12