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:
https://github.com/dotnet/sdk/blob/15c4fb1e5086e8a61876fd60b612a51cac1774c2/src/Cli/dotnet/Commands/Test/TestApplication.cs#L97
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
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 (
ArgumentListproperty), it cannot be used together withArgumentsproperty.API Proposal
API Usage
Real-world example is SDK:
https://github.com/dotnet/sdk/blob/15c4fb1e5086e8a61876fd60b612a51cac1774c2/src/Cli/dotnet/Commands/Test/TestApplication.cs#L97
There,
Module.RunProperties.Argumentsis 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.EscapeSingleArgimplementation 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