Prerequisites
Steps to reproduce
This was previously reported in #15261, which was inappropriately closed as by-design.
The purpose of --% (which only makes sense on Windows) is to copy the remainder of the command line verbatim to the process command line constructed behind the scenes, so as to provide a way to explicitly control the double-quoting for target executables that have non-standard quoting requirements.
As such, it should not be affected by the effective value of $PSNativeCommandArgumentPassing
(Note: It is debatable how arguments that come before --% on a given command line should be handled; for backward compatibility I think it would make the most sense to process them as if 'Legacy' were in effect; in other words: --% would be an implicit, command-scoped opt-in to $PSNativeCommandArgumentPassing = 'Legacy').
However, as of v7.3.0 it is, and the behavior is broken by default (the only way to make it work again is with $PSNativeCommandArgumentPassing = 'Legacy', which should not be necessary).
# Preparation: Create an executable that echoes the raw command line, as `.\echoCmdLine.exe`
# Note: Must call via *Windows PowerShell*
powershell -NoProfile {
Add-Type -OutputType ConsoleApplication -OutputAssembly ./echoCmdLine.exe -TypeDefinition @'
using System;
static class ConsoleApp {
static int Main(string[] args) {
Console.WriteLine(Environment.CommandLine);
return 0;
}
}
'@
}
# Set $PSNativeCommandArgumentPassing to something *other* than 'Legacy'
$PSNativeCommandArgumentPassing = 'Windows' # (the default on Windows)
# Using --%, pass *verbatim* `/p:Category="CI,Nightly"` on the process command line.
./echoCmdLine --% /p:Category="CI,Nightly"
Expected behavior
"C:\Users\jdoe\echoCmdLine.exe" /p:Category="CI,Nightly"
That is, the part of the original command line after --% should be copied as-is to the process command line.
That is how it has worked since v3 (when --% was introduced) and should continue to work, irrespective of the value of $PSNativeCommandArgumentPassing = 'Legacy', in both PowerShell editions.
Actual behavior
"C:\Users\jdoe\echoCmdLine.exe" "/p:Category=\"CI,Nightly\""
Note how the argument was inappropriately enclosed in "...", with embedded " escaped as \".
That is, the 'Standard' behavior was inappropriately used (although cmd.exe-style environment variables, e.g. %OS%, do still get expanded).
Error details
No response
Environment data
PowerShell Core 7.3.0 on Windows
Visuals
No response
Prerequisites
Steps to reproduce
This was previously reported in #15261, which was inappropriately closed as by-design.
The purpose of
--%(which only makes sense on Windows) is to copy the remainder of the command line verbatim to the process command line constructed behind the scenes, so as to provide a way to explicitly control the double-quoting for target executables that have non-standard quoting requirements.As such, it should not be affected by the effective value of
$PSNativeCommandArgumentPassing(Note: It is debatable how arguments that come before
--%on a given command line should be handled; for backward compatibility I think it would make the most sense to process them as if'Legacy'were in effect; in other words:--%would be an implicit, command-scoped opt-in to$PSNativeCommandArgumentPassing = 'Legacy').However, as of v7.3.0 it is, and the behavior is broken by default (the only way to make it work again is with
$PSNativeCommandArgumentPassing = 'Legacy', which should not be necessary).Expected behavior
"C:\Users\jdoe\echoCmdLine.exe" /p:Category="CI,Nightly"That is, the part of the original command line after
--%should be copied as-is to the process command line.That is how it has worked since v3 (when
--%was introduced) and should continue to work, irrespective of the value of$PSNativeCommandArgumentPassing = 'Legacy', in both PowerShell editions.Actual behavior
"C:\Users\jdoe\echoCmdLine.exe" "/p:Category=\"CI,Nightly\""Note how the argument was inappropriately enclosed in
"...", with embedded"escaped as\".That is, the
'Standard'behavior was inappropriately used (althoughcmd.exe-style environment variables, e.g.%OS%, do still get expanded).Error details
No response
Environment data
Visuals
No response