mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
This commit is contained in:
@@ -608,7 +608,8 @@ namespace Microsoft.PowerShell
|
||||
return (switchKey: string.Empty, shouldBreak: false);
|
||||
}
|
||||
|
||||
if (!CharExtensions.IsDash(switchKey[0]) && switchKey[0] != '/')
|
||||
char firstChar = switchKey[0];
|
||||
if (!CharExtensions.IsDash(firstChar) && firstChar != '/')
|
||||
{
|
||||
// then it's a file
|
||||
--argIndex;
|
||||
@@ -622,7 +623,7 @@ namespace Microsoft.PowerShell
|
||||
switchKey = switchKey.Substring(1);
|
||||
|
||||
// chop off the second dash so we're agnostic wrt specifying - or --
|
||||
if (!string.IsNullOrEmpty(switchKey) && CharExtensions.IsDash(switchKey[0]))
|
||||
if (!string.IsNullOrEmpty(switchKey) && CharExtensions.IsDash(firstChar) && switchKey[0] == firstChar)
|
||||
{
|
||||
switchKey = switchKey.Substring(1);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,47 @@ namespace PSTests.Parallel
|
||||
Assert.Contains("-noprofile", cpp.ErrorMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-Version")]
|
||||
[InlineData("--Version")]
|
||||
[InlineData("/Version")]
|
||||
public static void TestParameter_Dash_Or_Slash(params string[] commandLine)
|
||||
{
|
||||
var cpp = new CommandLineParameterParser();
|
||||
|
||||
cpp.Parse(commandLine);
|
||||
|
||||
Assert.False(cpp.AbortStartup);
|
||||
Assert.False(cpp.NoExit);
|
||||
Assert.True(cpp.NonInteractive);
|
||||
Assert.False(cpp.ShowBanner);
|
||||
Assert.False(cpp.ShowShortHelp);
|
||||
Assert.False(cpp.NoPrompt);
|
||||
Assert.True(cpp.ShowVersion);
|
||||
Assert.True(cpp.SkipProfiles);
|
||||
Assert.Null(cpp.ErrorMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/-Version")]
|
||||
[InlineData("-/Version")]
|
||||
public static void TestParameter_Wrong_Dash_And_Slash(params string[] commandLine)
|
||||
{
|
||||
var cpp = new CommandLineParameterParser();
|
||||
|
||||
cpp.Parse(commandLine);
|
||||
|
||||
Assert.True(cpp.AbortStartup);
|
||||
Assert.False(cpp.NoExit);
|
||||
Assert.False(cpp.NonInteractive);
|
||||
Assert.False(cpp.ShowBanner);
|
||||
Assert.True(cpp.ShowShortHelp);
|
||||
Assert.False(cpp.NoPrompt);
|
||||
Assert.False(cpp.ShowVersion);
|
||||
Assert.False(cpp.SkipProfiles);
|
||||
Assert.Contains(commandLine[0], cpp.ErrorMessage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("-Version")]
|
||||
[InlineData("-V")]
|
||||
|
||||
Reference in New Issue
Block a user