HMCL icon indicating copy to clipboard operation
HMCL copied to clipboard

CommandBuilder: Use more robust quoting

Open Artoria2e5 opened this issue 3 years ago • 7 comments
trafficstars

  • A while ago I brewed a pretty good quoting thing with unit tests on CMD (https://github.com/Artoria2e5/node/blob/fix!/child-process-args/test/parallel/test-child-process-spawnsync-shell-args.js). Use that. Specifically, the batch language and MSVCRT interprets the whole quoted thing a bit differently and we need to quote for both.
    • An example that I know breaks is "He\\\\o \\\"Wor\tld\\|<>&*\\" (java string). 这个按老方法 escape 出来是"He\\\o \\"Wor ld\|<>&*\" (raw string),cmd 没记错的话会认为重定向,但是新方法的"He\\o \\""Wor ld\|<>&*\\"不会。另外 cmd 测试起来很烦,内置echo 和外置程序行为不同,上面的测试用例是用 node -e 写了一个小的替换。
  • The shell quote is overcomplicated. The correct way is a lot like PWSH, in that we have a simple single quote.

Artoria2e5 avatar Jun 05 '22 04:06 Artoria2e5

Bash 单引号内不支持任何转义,包括对单引号本身的转义。你需要证明你对 parseBash 的更改是正确的。

huanghongxun avatar Jun 05 '22 05:06 huanghongxun

Bash 单引号内不支持任何转义,包括对单引号本身的转义。你需要证明你对 parseBash 的更改是正确的。

对,所以把它换成:

  • ' 关闭单引号环境。
  • \' 正常环境转义。
  • ' 打开继续单引号。

可以参考 python shlex.quote,同样的道理,但是用双引号包中间的单引号:https://github.com/python/cpython/blob/3.10/Lib/shlex.py#L334

Artoria2e5 avatar Sep 07 '22 07:09 Artoria2e5

不愿意 merge upstream,因为名字不如我改得好。<_<

Artoria2e5 avatar Sep 07 '22 07:09 Artoria2e5

@Artoria2e5 冲突了!快来修

burningtnt avatar Aug 08 '23 03:08 burningtnt

xjb 改名!

Artoria2e5 avatar Aug 08 '23 07:08 Artoria2e5

Checkstyle 炸喽 @Artoria2e5 哈哈哈,Java CI 也炸了

burningtnt avatar Aug 08 '23 08:08 burningtnt

到处改名指望手动网页 merge 能找全本来就是扯淡……

Artoria2e5 avatar Aug 08 '23 13:08 Artoria2e5