由于glib.string.escape()的文档
Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\v', '\' and '"' in the string source by inserting a '\' before them.
Additionally all characters in the range 0x01-0x1F (everything below SPACE) and in the range 0x7F-0xFF (all non-ASCII chars) are replaced with a '\' followed by their octal representation. Characters supplied in exceptions are not escaped.
现在我想要不 eacape“0x7F-0xFF”字符。如何编写异常(exception)部分?
我的示例代码不起作用。
shellcmd = "bash -c \""+file.get_string(title,"List").escape("0x7F-0xFF")+"\"";
print("shellcmd: %s\n", shellcmd);
Process.spawn_command_line_sync (shellcmd,
out ls_stdout, out ls_stderr, out ls_status);
if(ls_status!=0){ list = ls_stderr.split("\n"); }
else{ list = ls_stdout.split("\n"); }
这有效。
shellcmd = "bash -c \""+file.get_string(title,"Check").replace("\"","\\\"")+"\"";
最佳答案
实际上,您必须将字符 0x7f
放入 exceptions
参数中的 0xff
中。所以类似:
shellcmd = "bash -c \""+file.get_string(title,"List").escape("\x7F\x80\x81\x82…\xfe\xff")+"\"";
您需要手动列出它们。
更广泛地查看您的代码,您似乎正在构建一个要运行的命令。这是一个非常糟糕的主意,你绝对不应该这样做。它对code injection敞开大门。 。使用 Process.spawn_sync() 并向其传递一个参数向量。
关于gtk - 使用 glib.string.escape() 时如何转义特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59971175/