Python bug:输入提示中的null字节

Kos*_*lak 10 python prompt input readline nul

我发现了

input('some\x00 text')
Run Code Online (Sandbox Code Playgroud)

将提示some而不是some text.

从消息来源,我发现这个函数使用C函数PyOS_Readline,它在NULL字节后忽略提示中的所有内容.

来自PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt):

fprintf(stderr, "%s", prompt);
Run Code Online (Sandbox Code Playgroud)

https://github.com/python/cpython/blob/3.6/Python/bltinmodule.c#L1989 https://github.com/python/cpython/blob/3.6/Parser/myreadline.c#L251

这是一个错误还是有原因的?

问题:http://bugs.python.org/issue30431

Ray*_*ger 2

函数签名几乎需要一个以NUL结尾的 C 字符串PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt),因此在不更改 API 和破坏与 GNU readline 的互操作性的情况下,对此无能为力。