Repository navigation
Closed
Labels
Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
Description
Running Get-Command on a string containing only spaces results in the cmdlet crashing with an IndexOutOfRangeException rather than throwing a proper exception (such as a CommandNotFoundException) describing what was wrong with your input.
Steps to reproduce
Get-Command " "Expected behavior
A CommandNotFoundException specifying that the term is not recognized as the name of a cmdlet, function, script file or operable program
Actual behavior
An IndexOutOfRangeException due to an explosion in CommandSearcher.DoPowerShellRelativePathLookup
C:\> Get-Command " "
Get-Command : Index was outside the bounds of the array.Exception stack trace:
at System.Management.Automation.CommandSearcher.DoPowerShellRelativePathLookup()
at System.Management.Automation.CommandSearcher.ProcessPathSearchState()
at System.Management.Automation.CommandSearcher.MoveNext()
at Microsoft.PowerShell.Commands.GetCommandCommand.FindCommandForName(SearchResolutionOptions options, String commandName, Boolean isPattern, Boolean emitErrors, Int32& currentCount, Boolean& isDuplicate)
at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable`1 commandNames)
at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands()
at Microsoft.PowerShell.Commands.GetCommandCommand.ProcessRecord()
at System.Management.Automation.Cmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
Environment data
Name Value
---- -----
PSVersion 7.0.0-preview.1
PSEdition Core
GitCommitId 7.0.0-preview.1
OS Microsoft Windows 6.1.7601 Service Pack 1
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0.}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Seems to affect all versions of PowerShell, at the very least going back as far as Windows PowerShell 5.1
Reacted by Michael Klement
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdletsgeneral cmdlet issues
Activity
MartinGC94 commentedon Dec 30, 2022
This doesn't happen on 7.4.0 preview 1, instead I get the error:
Like I would expect