You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Arguments for external executables aren't correctly escaped #1995
Why do you think that "\"a\"" the expected behavior? My understanding of PowerShell escapes says that the actual behavior is the correct and expected behavior. ""a"" is a pair of quotes surrounding an escaped pair of quotes surrounding an a, so PowerShell interprets the outer unescaped pair as "this is a string argument" and so drops them, then interprets the escaped pair as escaped quotes and so keeps them, leaving you with "a". At no point was a \ added to the string.
The fact that Bash uses \ as an escape character is irrelevant. In PowerShell, the escape character is a backtick. See PowerShell escape characters.
If you want to pass literally "\"a\"", I believe you would use:
Andy Jordan (@andschwa)
Yes, escapes works fine for internal cmdlets, but things get weird when communicate with native binaries, especially on Windows.
When running native.exe ""a"", the ARGV[1] should be
No, We still need to add a backslash before a backtick-escaped double quote? This does not solve the double-escaping problem. (That is, we have to escape a double quote for both PowerShell and CommandLineToArgvW.)
This seems like a feature request that if implemented could break a large number of already existing PowerShell scripts that use the required double escaping, so extreme care would be required with any solution.
$ ./a "a b"
Command Line : "Z:\playground\ps-cmdline\a.exe" "a b"
argv[0]: Z:\playground\ps-cmdline\a.exe
argv[1]: a b
$ ./a 'a b'
Command Line : "Z:\playground\ps-cmdline\a.exe" "a b"
argv[0]: Z:\playground\ps-cmdline\a.exe
argv[1]: a b
$ ./a 'a"b'
Command Line : "Z:\playground\ps-cmdline\a.exe" a"b
argv[0]: Z:\playground\ps-cmdline\a.exe
argv[1]: ab
$ ./a 'a"b"c'
Command Line : "Z:\playground\ps-cmdline\a.exe" a"b"c
argv[0]: Z:\playground\ps-cmdline\a.exe
argv[1]: abc
$ ./a 'a\"b\"c'
Command Line : "Z:\playground\ps-cmdline\a.exe" a\"b\"c
argv[0]: Z:\playground\ps-cmdline\a.exe
argv[1]: a"b"c
Reacted by Jiashuo Li, Tatsunori Uchino, bb010g and Giorgi Chakhidze
In my opinion, the bash/powershell behavior makes more sense than the cmd behavior. In the above example, the quotes are intended for the shell interpreter, they are not part of the user's input. The shell's job is to pass each value as a String to the command that it calls. It is the executable/command scripts responsibility to re-escape as necessary before shelling out again.
Furthermore this seems to be a specific behavior related to cmd.exe calling command scripts.
importsysprint(sys.argv)
C:\Users\bburns>py test.py 'a|b''b'' is not recognized as an internal or external command,operable program or batch file.C:\Users\bburns>py test.py 'a&b'['test.py', "'a"]'b'' is not recognized as an internal or external command,operable program or batch file.
This issue is about passing arguments to native executables that support passing arguments. The executable cmd.exe is not one of them, it uses the whole command line instead. The only reliable way to call cmd.exe is to print the expected command line out into a temporary command script and run that script without any arguments.
Activity
andyleejordan commentedon Aug 31, 2016
Why do you think that
"\"a\""the expected behavior? My understanding of PowerShell escapes says that the actual behavior is the correct and expected behavior.""a""is a pair of quotes surrounding an escaped pair of quotes surrounding ana, so PowerShell interprets the outer unescaped pair as "this is a string argument" and so drops them, then interprets the escaped pair as escaped quotes and so keeps them, leaving you with"a". At no point was a\added to the string.The fact that Bash uses
\as an escape character is irrelevant. In PowerShell, the escape character is a backtick. See PowerShell escape characters.If you want to pass literally
"\"a\"", I believe you would use:be5invis commentedon Aug 31, 2016
Andy Jordan (@andschwa)
Yes, escapes works fine for internal cmdlets, but things get weird when communicate with native binaries, especially on Windows.
When running
native.exe ""a"", the ARGV[1] should be(three characters)
instead of
(one character).
be5invis commentedon Aug 31, 2016
Currently to make
native.execorrectly receive an ARGV with two quotes and anacharacter, you have to use this weird call:andyleejordan commentedon Aug 31, 2016
Ah, I see. Re-opening.
andyleejordan commentedon Aug 31, 2016
Out of a strong curiosity, what happens if you try a build using #1639?
be5invis commentedon Aug 31, 2016
Andy Jordan (@andschwa) The same. You HAVE to double-esacpe to satisify both PowerShell and
CommandLineToArgvW. This line:results a StartProcess equalivent to cmd
andyleejordan commentedon Sep 19, 2016
Belleve (@be5invis) Douglas Thrift (@douglaswth) is this resolved via #2182?
be5invis commentedon Sep 20, 2016
vors commentedon Sep 20, 2016
Since
""a""is equal to'"a"', do you suggest thatnative.exe '"a"'should result in"\"a\""?douglaswth commentedon Sep 20, 2016
This seems like a feature request that if implemented could break a large number of already existing PowerShell scripts that use the required double escaping, so extreme care would be required with any solution.
be5invis commentedon Sep 20, 2016
sergei (@vors) Yes.
Douglas Thrift (@douglaswth) The double-escaping is really silly: why do we need the “inner” escapes made in the DOS era?
be5invis commentedon Sep 20, 2016
sergei (@vors) Douglas Thrift (@douglaswth)
This is a the C code used to show GetCommandLineW and CommandLineToArgvW results:
be5invis commentedon Sep 20, 2016
Here is the result
218 remaining items
mklement0 commentedon May 6, 2021
A decision regarding the accommodations on Windows has been made: #15143 (comment).
SteveL-MSFT commentedon Aug 11, 2022
This appears to be fixed in 7.3:
jiasli commentedon Aug 11, 2022
Thanks a lot Steve Lee (@SteveL-MSFT). May I know which PR is responsible for the fix?
jiasli commentedon Aug 11, 2022
I can verify double quotes are escaped correctly in v7.3.0-preview.6 when calling a
.exe.However, special characters (
",|,&) are still not escaped correctly when invoking acmdscript. Consider a very simply scripttest.cmd:For
|, runningtest.cmdin PowerShell v7.3.0-preview.6 gives:This differs from the behavior of Command Prompt:
This causes problem for Azure CLI when there is
|or&in argument value: Azure/azure-cli#20972For
", runningtest.cmdin PowerShell v7.3.0-preview.6 gives:This differs from the behavior of Command Prompt:
rivy commentedon Aug 11, 2022
As noted by Jiashuo Li (@jiasli), this issue is not actually fixed.
brendandburns commentedon Aug 11, 2022
The PowerShell behavior here is the same as
bashtest.sh:In my opinion, the bash/powershell behavior makes more sense than the
cmdbehavior. In the above example, the quotes are intended for the shell interpreter, they are not part of the user's input. The shell's job is to pass each value as a String to the command that it calls. It is the executable/command scripts responsibility to re-escape as necessary before shelling out again.brendandburns commentedon Aug 11, 2022
Furthermore this seems to be a specific behavior related to
cmd.execalling command scripts.yecril71pl commentedon Sep 16, 2022
This issue is about passing arguments to native executables that support passing arguments. The executable
cmd.exeis not one of them, it uses the whole command line instead. The only reliable way to callcmd.exeis to print the expected command line out into a temporary command script and run that script without any arguments.Fix npm "Unknown command: pm" in build-play-aab on Windows PowerShell…
feat!: add the print statement and static modifier
Acik temada terminal acilirken 'Invalid JSON provided to --settings' …