You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IndexOutOfRange exception when parsing empty argument #1533
I ran into this while updating the SDK to the latest version. For the input dotnet add "" (note the explicitly empty argument) the tokenizer throws an IndexOutOfRangeException:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.String.get_Chars(Int32 index)
at System.CommandLine.Parsing.StringExtensions.GetPrefixLength(String alias)
at System.CommandLine.Parsing.StringExtensions.Tokenize(IReadOnlyList`1 args, CommandLineConfiguration configuration)
at System.CommandLine.Parsing.Parser.Parse(IReadOnlyList`1 arguments, String rawInput)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient) in C:\Users\chethusk\OSS\dotnet-sdk\src\Cli\dotnet\Program.cs:line 130
at Microsoft.DotNet.Cli.Program.Main(String[] args) in C:\Users\chethusk\OSS\dotnet-sdk\src\Cli\dotnet\Program.cs:line 76
What's happening here is that in the tokenization loop S.CL eventually creates an Token of type Argument with the empty string as the value, and in the constructor of the Token type GetPrefixLength is called on that value, which indexes into the value directly without checks.
I feel like I could be holding it wrong by passing empty arguments in, but this test passed prior to this update (it tests that a 'missing required argument' message is shown). Should this method be made more defensive, or should the tokenization loop remove the empty token entirely, or some other resolution?
Activity
fix dotnet#1533
fix dotnet#1533