mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add null check for args in CommandLineParser (#13451)
This commit is contained in:
@@ -712,6 +712,14 @@ namespace Microsoft.PowerShell
|
||||
throw new InvalidOperationException("This instance has already been used. Create a new instance.");
|
||||
}
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(args), CommandLineParameterParserStrings.NullElementInArgs);
|
||||
}
|
||||
}
|
||||
|
||||
// Indicates that we've called this method on this instance, and that when it's done, the state variables
|
||||
// will reflect the parse.
|
||||
_dirty = true;
|
||||
|
||||
@@ -219,4 +219,7 @@ Valid formats are:
|
||||
<data name="STANotImplemented" xml:space="preserve">
|
||||
<value>Parameter -STA is not supported on this platform.</value>
|
||||
</data>
|
||||
<data name="NullElementInArgs" xml:space="preserve">
|
||||
<value>The specified arguments must not contain null elements.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -65,6 +65,15 @@ namespace PSTests.Parallel
|
||||
Assert.Throws<System.InvalidOperationException>(() => cpp.Parse(new string[0]));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("arg1", null, "arg3")]
|
||||
public static void Test_ARGS_With_Null(params string[] commandLine)
|
||||
{
|
||||
var cpp = new CommandLineParameterParser();
|
||||
|
||||
Assert.Throws<System.ArgumentNullException>(() => cpp.Parse(commandLine));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("noexistfilename")]
|
||||
public static void TestDefaultParameterIsFileName_Not_Exist(params string[] commandLine)
|
||||
|
||||
Reference in New Issue
Block a user