-
-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python IDLE stops outputting a string on encountering a null character both for STDOUT and STDERR #119614
Comments
|
I verified the behavior on 3.13 on Windows. And on Mac (at least the print part). It may be a tk/tkinter issue somehow but I am not sure. I hypothesized that it was a socket issue, but starting IDLE in CommandPrompt with |
|
Maybe we should try directly writing a tcl script next to test whether it's a problem in the tkinter binding or in the underlying tk? |
|
In 3.6: >>> import tkinter
>>> b = tkinter.Button(text='abc\0def')
>>> b.tk.call(str(b), 'cget', '-text')
'abc\x00def'
>>> b.tk.eval(str(b) + ' cget -text')
'abc\x00def'In 3.7: >>> import tkinter
>>> b = tkinter.Button(text='abc\0def')
>>> b.tk.call(str(b), 'cget', '-text')
'abc\x00def'
>>> b.tk.eval(str(b) + ' cget -text')
'abc'And only the portion before This looks like a weird Tcl/Tk bug. It knows that there are characters past NUL, and There are two internal representations of strings in Tcl. Before 3.7 all strings were created with We need to check whether this issue is solved in Tcl 8.7 or 9.0. If it is solved on their side, we do not need to do anything. Otherwise we will need to use some workarounds which will never be perfect: the null character can be removed or replaced with some weird sequence, and this will not be consistent across platforms and the way of using the string. |
|
Are either 8.7 or 9.0 near release, so we can use them? |
…ers in Tkinter Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj().
|
Nothing was changed in 8.6.14, 8.7 and 9.0. I reported a bug in Tcl: https://core.tcl-lang.org/tcl/tktview/8c4082563d. But it seems that they are no going to change anything here. #120909 adds a workaround from our side. |
… Tkinter (GH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj().
…ers in Tkinter (pythonGH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj(). (cherry picked from commit c38e2f6) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ers in Tkinter (pythonGH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj(). (cherry picked from commit c38e2f6) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
Thank you for fixing this non-trivial issue. For |
…ers in Tkinter (pythonGH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj().
…ers in Tkinter (pythonGH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj().
…ers in Tkinter (pythonGH-120909) Now the null character is always represented as \xc0\x80 for Tcl_NewStringObj().

Bug report
Bug description:
I noticed that if you pass a string containing a null character (
\0) as an argument to the built-inprintfunction, IDLE only outputs that string to the point of the null character, then it jumps to outputting the next argument to print as if that string has actually ended. This is not consistent with the behavior when using the Python interpreter directly in a terminal, where the null character is usually printed as a space-looking character and does not terminate the string. If further arguments to the sameprintcall also contains null characters, the same thing happens (it'll skip to the next argument immediately on encountering a\0). If thesepstring contains a null character, it'll also only print to the point of the null character before starting to print the next positional argument, as if thesepstring had actually ended there. The same thing happens with theendstring. And the same behavior happens when callingsys.stdout.writedirectly. Writing to STDERR has the same effect of stuff getting cut off on the null character. Basically anything that results in text being outputted to IDLE triggers this bug. Maybe tk's Text widget treats null characters as string terminators because tk is written in C? By the way, the bug works the same both in interactive mode and running a file. Below's an example, run it in IDLE and you should get the same erroneous output:Version Info:
I have tested this on the 64 bit "Windows Installer" versions of Python
3.9.7and3.12.3. My OS isWindows 10 Version 22H2, build 19045.4412. Thesys.versionvalue on the 3.9.7 version is3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)], and the 3.12.3 version is3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]. Hope this helps.CPython versions tested on:
3.9, 3.12
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: