mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Remove managed CommandLineToArgv
It is entirely unused.
This commit is contained in:
@@ -367,65 +367,6 @@ namespace System.Management.Automation
|
||||
// TODO:PSL clean this up
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This models the native call CommandLineToArgvW in managed code.
|
||||
/// </summary>
|
||||
internal static string[] CommandLineToArgv(string command)
|
||||
{
|
||||
StringBuilder arguments = new StringBuilder();
|
||||
int len = command.Length;
|
||||
IList<string> returnList = new List<string>();
|
||||
bool inquote = false;
|
||||
char current = '\0';
|
||||
|
||||
for (int argIndex = 0; argIndex < len; argIndex++)
|
||||
{
|
||||
current = command[argIndex];
|
||||
|
||||
if (current.Equals('"'))
|
||||
{
|
||||
// Treat anything in quotes as a single argument
|
||||
// Because C# treats quotes differently than C++, instead of counting the slashes
|
||||
// it makes more sense to count the quotes.
|
||||
inquote = !inquote;
|
||||
arguments.Append('"');
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we're inside a quote, add the current character and cycle through
|
||||
if (inquote && !current.Equals('"'))
|
||||
{
|
||||
arguments.Append(current.ToString());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current.Equals("\\"))
|
||||
{
|
||||
arguments.Append("\\");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(current.ToString()))
|
||||
{
|
||||
if (arguments.Length > 0)
|
||||
{
|
||||
returnList.Add(arguments.ToString());
|
||||
arguments.Clear();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// All other exclusion scenarios being exhausted, append the current character.
|
||||
arguments.Append(current.ToString());
|
||||
}
|
||||
|
||||
// add the final object to the arguments list
|
||||
returnList.Add(arguments.ToString());
|
||||
arguments.Clear();
|
||||
|
||||
return returnList.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Unix
|
||||
|
||||
@@ -255,112 +255,5 @@ namespace PSTests
|
||||
File.Delete(path);
|
||||
File.Delete(link);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineArgvReturnsAnElement()
|
||||
{
|
||||
string testCommand= "Today";
|
||||
|
||||
string[] retval = Platform.CommandLineToArgv(testCommand);
|
||||
|
||||
Assert.Equal(1, retval.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineArgvWWithSpaces()
|
||||
{
|
||||
string testCommand= "Today is a good day or is it";
|
||||
|
||||
string[] retval = Platform.CommandLineToArgv(testCommand);
|
||||
|
||||
Assert.Equal("Today", retval[0]);
|
||||
Assert.Equal("is", retval[1]);
|
||||
Assert.Equal("a", retval[2]);
|
||||
Assert.Equal("good", retval[3]);
|
||||
Assert.Equal("day", retval[4]);
|
||||
Assert.Equal("or", retval[5]);
|
||||
Assert.Equal("is", retval[6]);
|
||||
Assert.Equal("it", retval[7]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineToArgvWTabsAreTreatedAsSpaces()
|
||||
{
|
||||
string testCommand = "Today \t is a good day";
|
||||
|
||||
string[] retval = Platform.CommandLineToArgv(testCommand);
|
||||
|
||||
Assert.Equal("Today", retval[0]);
|
||||
Assert.Equal("is", retval[1]);
|
||||
Assert.Equal("a", retval[2]);
|
||||
Assert.Equal("good", retval[3]);
|
||||
Assert.Equal("day", retval[4]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineToArgvWQuotesAreArgs()
|
||||
{
|
||||
string testCommand = "Today is \"a good\" day";
|
||||
|
||||
string[] retval = Platform.CommandLineToArgv(testCommand);
|
||||
|
||||
Assert.Equal(4, retval.Length);
|
||||
Assert.Equal("Today", retval[0]);
|
||||
Assert.Equal("is", retval[1]);
|
||||
Assert.Equal("\"a good\"", retval[2]);
|
||||
Assert.Equal("day", retval[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineToArgvWEvenNumberBackSlashes()
|
||||
{
|
||||
string test1 = "a\\b c d";
|
||||
string test2 = "a\\b\\c d";
|
||||
string test3 = "a \\b\\c\\d";
|
||||
string test4 = "a\\\\\\b";
|
||||
string[] retval;
|
||||
|
||||
retval = Platform.CommandLineToArgv(test1);
|
||||
|
||||
Assert.Equal(3, retval.Length);
|
||||
Assert.Equal("a\\b", retval[0]);
|
||||
Assert.Equal("c", retval[1]);
|
||||
Assert.Equal("d", retval[2]);
|
||||
|
||||
retval = Platform.CommandLineToArgv(test2);
|
||||
|
||||
Assert.Equal(2, retval.Length);
|
||||
Assert.Equal("a\\b\\c", retval[0]);
|
||||
Assert.Equal("d", retval[1]);
|
||||
|
||||
retval = Platform.CommandLineToArgv(test3);
|
||||
|
||||
Assert.Equal(2, retval.Length);
|
||||
Assert.Equal("a", retval[0]);
|
||||
Assert.Equal("\\b\\c\\d", retval[1]);
|
||||
|
||||
retval = Platform.CommandLineToArgv(test4);
|
||||
|
||||
Assert.Equal(1, retval.Length);
|
||||
Assert.Equal("a\\\\\\b", retval[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandLineToArgvwOddNumberWithBackSlashes()
|
||||
{
|
||||
string test1 = "a\\\"b";
|
||||
string test2 = "a\\\\\\\"b";
|
||||
string[] retval;
|
||||
|
||||
retval = Platform.CommandLineToArgv(test1);
|
||||
|
||||
Assert.Equal(1, retval.Length);
|
||||
Assert.Equal("a\\\"b", retval[0]);
|
||||
|
||||
retval = Platform.CommandLineToArgv(test2);
|
||||
|
||||
Assert.Equal(1, retval.Length);
|
||||
Assert.Equal("a\\\\\\\"b", retval[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user