STINNER Victor <vstin...@python.org> added the comment:
On my Fedora 33 (readline-8.0-5.fc33.x86_64), I enabled the bracketed paste mode by adding "set enable-bracketed-paste" on to my ~/.inputrc config file. When I test https://thejh.net/misc/website-terminal-copy-paste : the evil command is no long executed. If I copy/paste "1+1" and "2+2" commands (two lines pasted at once) manually in the Python REPL, they are no longer executed immediately, Python waits for me pressing ENTER to execute, *as expected*: ---- $ ./python Python 3.10.0a5+ (heads/master:fcbe0cb04d, Feb 15 2021, 10:30:10) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 1+1 2+2 ---- But using "./python -i < commands", each line is executed immediately and Python exits after displaying the results: --- $ cat commands 1+1 2+2 $ ./python -i < commands Python 3.10.0a5+ (heads/master:fcbe0cb04d, Feb 15 2021, 10:30:10) >>> 2 >>> 4 >>> --- If I disable again bracketed mode (ex: remove ~/.inputrc file in my case), when I copy/paste manually the two commands at once, they are executed again, as expected: --- $ ./python >>> 1+1 2 >>> 2+2 4 --- The bracketed paste mode can be enabled explicitly in Python with this patch to simulate readline 8.1 default behavior: diff --git a/Modules/readline.c b/Modules/readline.c index c900e07954..ce8662c000 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -217,6 +217,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj) errno = rl_read_init_file(NULL); if (errno) return PyErr_SetFromErrno(PyExc_OSError); + rl_variable_bind ("enable-bracketed-paste", "on"); Py_RETURN_NONE; } All of these behavior look consistent, correct and expected. Note: When I redirect Python output into a file, I cannot see "\e[?2004h" (likely because stdout is not a TTY if it's redirected into a file), so I'm not sure how to check if this escape sequence is injected in Python stdout or not. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42819> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com