-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Background and motivation
The core logic is in an internal PasteArguments.AppendArgument
. But it's not exposed directly for users usage.
While ProcessStartInfo today already supports passing a list of unescaped arguments (ArgumentList
property), it cannot be used together with Arguments
property.
API Proposal
namespace System.Diagnostics;
public class ProcessStartInfo
{
public static string EscapeArgument(string argument);
}
API Usage
// Fancy the value
var info = new ProcessStartInfo()
{
FileName = ...;
}
var builder = new StringBuilder();
builder.Append(myAlreadyEscapedArgumentsComingFromElsewhere);
foreach (var arg in listOfUnescapedArguments)
{
builder.Append(ProcessStartInfo.EscapeArgument(arg));
}
info.Arguments = builder.ToString();
Real-world example is SDK:
There, Module.RunProperties.Arguments
is already a single string which can contain multiple arguments like --report-trx --results-directory "Path Containing Spaces"
which is already escaped properly.
Then, there are multiple more arguments that need to be constructed and are not escaped.
NOTE: ArgumentEscaper.EscapeSingleArg
implementation seems like it's already diverging from the implementation in dotnet/runtime. And somewhere in dotnet/msbuild there is even another implementation somewhere.
Alternative Designs
Allow both ProcessStartInfo.Arguments and ArgumentList to be used together.
Risks
No response