-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
normalize command line arguments #4724
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(comments left separately. thanks for looking into this!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only not signing off because of the (arg0name.length() < 2U || std::towlower(arg0name.front()) != L'w')
thing. Otherwise I'm happy with this.
After thinking twice we might actually need an alternative way to preserve quotes in an argument. E.g. in commands that shall be executed in a tab.
Doubling the quotes is not unusual on Windows. That's what you have to do in VB strings or what you have to pass to find.exe. And it doesn't lead to unbalanced quotation marks in the calling shell. However, consider to kick me out at this point and close #4571 as by design. |
The answer to this is typically "somebody made a decision 30 years ago and now it exists, and its deficiencies are not adequately documented such that people would know to stop using it." Consider some other parts of the Win32 API surface... |
Part of the problem is that we're not launching via |
We're a Windows subsystem application. Windows subsystem applications use wWinMain. If there's a reasonable way for us to use |
The internal parser that generates |
Couple points:
We need to be sensitive of what the shell is splitting and what the recipient is splitting, especially when we are discussing a change to the algorithm on the receiving side. |
This PR addresses the quirk that |
I dunno if that holds on Windows for Windows tools though. Ideally, we would have something like exec and parameter splitting would have been done before we were even started (where quotes wouldn’t be an issue), but as it stands we don’t, and a Windows path is making it into my process with a \ and a “ in it, and something has to handle that appropriately. Escaping should have happened outside my process, and unquoting should have happened outside my process, but that’s just not the world we live in in Windows. We will probably need our own parser anyway: these command strings are going to come from places that aren’t just argv/the environment block in the future(1) and the quicker we can converge how they’re handled the better the experience will be. 1: my phone browser isn’t letting me do the GitHub issue reference search, but we have one for supporting |
Anyway... if our options are “fight the holy war to make all argument parsing in Windows happen before spawn instead of after spawn, and then wait ten years for the operating system parts to shake out” or “have our own parser for now that works on all existing versions for the use cases we need” I know which one I’m voting for |
I'm sure it was not intended to be an error. Indeed it is still a possibility to preserve a quotation mark in an argument. But we already have an alternative by doubling them. And doubling the backslash is the way out with the current parser. But think about an argument like |
Command line options are supported for a couple of months now. I guess meanwhile users are used to escaping the trailing backslash or they just append a point. Changing the bahavior now may break scripts of too many people. |
Summary of the Pull Request
Use
""
instead of treating\"
as escaped"
.Try to ensure that the app name is always the argument with index 0.obsoletReferences
#4632
PR Checklist
wt.exe
is alwaysargv[0]
#4170 in terms of having the decision that we don't try to resolve it programmatically)Detailed Description of the Pull Request / Additional comments
""
rather than\"
as escaped quotation mark to preserve it in the argumentCheck if at least one command line argument has been received. Check if the first argument is reasonable to represent the own call. If either of these isn't true, add the app path as first argument.obsoletValidation Steps Performed
-d
and quoted paths with trailing backslash.CreateProcess
function in a test app to simulate the missing application name in the first argument.