Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ internal void Parse(string[] args)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
9 changes: 9 additions & 0 deletions test/xUnit/csharp/test_CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public static void Test_Throws_On_Reuse()
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)
Expand Down