-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
In Windows, Trailing Backslash In Quoted Path Argument Leads to Wrong Command-line Parsing #72653
Comments
This sounds like Rust is behaving correctly though? Isn't this a bug in Powershell? |
Given that Rust's behavior matches |
Closing as expected behavior. |
There are numerous problems with powershell quoting that is exarcebated with backslash. One of them is that ps will remove quotes if there are no spaces in the argument as detailed here: PowerShell/PowerShell#11295 (comment)
So if you are depending on Rust's built-in windows command-line parser, your C/C++ compiled program's argc, argv arguments, or using explicitly functions like CommandLineToArgvW, you will get different results. Notably, without the double-quotes in the first example, it will not convert the pairs of backslash into a single backslash. Command-prompt (cmd) passes the command-line string as is and so you get a consistent (ie, predictable) parsing of your arguments. So you may want to run your rust binary using cmd on Windows. |
If a rust windows program has a command-line argument like this:
.\myapp -p "C:\Program Files\" -v
, it will be parsed as follows: ['.\myapp', '-p', 'C:\\Program Files\\" -v'] instead of ['.\myapp', '-p', 'C:\\Program Files\\', '-v'].Looking over rust code, this is due to rust adhering to Microsoft standard:
And the link states:
So everything is behaving to spec. The problem is that if a user is running my app in powershell, tab-completion will automatically add in the trailing backslash in quoted paths. So I have to explain that this doesn't work.
Some observations:
dir "C:\Program Files\" /B
CommandLineToArgvW
through the winapi crate but it also seems to have the same problem.The text was updated successfully, but these errors were encountered: