Repository navigation
Pasting 🏳️🌈 crashes the new Python REPL #121609
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Crash report
What happened?
To reproduce, start the new Python REPL in 3.13.0b3 and start to assign a string:
$ python3.13
Python 3.13.0b3 (main, Jul 2 2024, 13:24:06) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> flag = 'Then paste 🏳️🌈 and this happens:
$ python3.13
Python 3.13.0b3 (main, Jul 2 2024, 13:24:06) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> flag = 'Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/__main__.py", line 3, in <module>
__pyrepl_interactive_console()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/main.py", line 55, in interactive_console
run_interactive(namespace)
~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/simple_interact.py", line 144, in run_multiline_interactive_console
statement = multiline_input(more_lines, ps1, ps2)
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/readline.py", line 385, in multiline_input
return reader.readline()
~~~~~~~~~~~~~~~^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 768, in readline
self.handle1()
~~~~~~~~~~~~^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 751, in handle1
self.do_cmd(cmd)
~~~~~~~~~~~^^^^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 695, in do_cmd
self.refresh()
~~~~~~~~~~~~^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 672, in refresh
self.screen = self.calc_screen()
~~~~~~~~~~~~~~~~^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/completing_reader.py", line 261, in calc_screen
screen = super().calc_screen()
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 360, in calc_screen
l, l2 = disp_str(line)
~~~~~~~~^^^^^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/reader.py", line 61, in disp_str
b.append(str_width(c))
~~~~~~~~~^^^
File "/home/trey/.pyenv/versions/3.13.0b3/lib/python3.13/_pyrepl/utils.py", line 10, in str_width
if ord(c) < 128:
~~~^^^
TypeError: ord() expected a character, but string of length 6 foundThis looks like an issue with multiple-character glyphs, as 🏴 causes the same issue.
I found myself at my system command prompt after this (Python had exited).
I initially tested this on Python 3.13.0b3, but I also reproduced the issue on the current main branch.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.0b3 (main, Jul 2 2024, 13:24:06) [GCC 11.4.0]
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
itamaro commentedon Jul 11, 2024
confirmed the reproducer indeed crashes the repl on 3.14 (main branch) on macOS too (with a debug build and GIL disabled, ftr)
itamaro commentedon Jul 11, 2024
for comparison, this is how it behaves on 3.12:
the
'🏳️\U+200D🌈'sequence is what gets pasted when I paste the pride flag, not something I typed manuallyEclips4 commentedon Jul 11, 2024
Hello! The
type-crashlabel is intended for bugs where the interpreter exits with a segmentation fault or something similar.The
type-buglabel is more applicable here since there is no hard crash of the interpreter.mgmacias95 commentedon Jul 13, 2024
I'm working on this :)
ods commentedon Jul 13, 2024
@mgmacias95 It's just a typo, one extra copy-pasted line
mgmacias95 commentedon Jul 13, 2024
If that line is removed the emoji is pasted as:
In prior versions of python it was pasted correctly:
ods commentedon Jul 13, 2024
It looks like intended behaviour: the code explicitly replaces unprintable control/format/etc characters with their unicode escape sequence.
gh-121609: Fix pasting of characters containing unicode character joi…
pythongh-121609: Fix pasting of characters containing unicode charact…
[3.13] gh-121609: Fix pasting of characters containing unicode charac…
hugovk commentedon Jul 14, 2024
Thank you @treyhunner for the report, @mgmacias95 for the fix, and everyone else for the investigation!
pythongh-121609: Fix pasting of characters containing unicode charact…