Skip to content
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

CommandBuilder: Use more robust quoting #1540

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Artoria2e5
Copy link
Contributor

@Artoria2e5 Artoria2e5 commented Jun 5, 2022

  • 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.

* 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\\|<>&*\\`.
* The shell quote is overcomplicated. The correct way is a lot like PWSH, in that we have a simple single quote.
@Artoria2e5 Artoria2e5 marked this pull request as ready for review June 5, 2022 04:16
@huanghongxun
Copy link
Collaborator

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

@Artoria2e5
Copy link
Contributor Author

Artoria2e5 commented Sep 7, 2022

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

对,所以把它换成:

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

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

@Artoria2e5
Copy link
Contributor Author

Artoria2e5 commented Sep 7, 2022

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

@burningtnt
Copy link
Member

burningtnt commented Aug 8, 2023

@Artoria2e5 冲突了!快来修

@Artoria2e5
Copy link
Contributor Author

xjb 改名!

@burningtnt
Copy link
Member

burningtnt commented Aug 8, 2023

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

@Artoria2e5
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants