mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Write proper error messages for Get-Command ' ' (#13564)
This commit is contained in:
@@ -1087,7 +1087,7 @@ namespace System.Management.Automation
|
||||
string? result = null;
|
||||
|
||||
if (_context.EngineSessionState != null &&
|
||||
_context.EngineSessionState.ProviderCount > 0)
|
||||
_context.EngineSessionState.ProviderCount > 0 && _commandName.Length != 0)
|
||||
{
|
||||
// NTRAID#Windows OS Bugs-1009294-2004/02/04-JeffJon
|
||||
// This is really slow. Maybe since we are only allowing FS paths right
|
||||
@@ -1099,7 +1099,9 @@ namespace System.Management.Automation
|
||||
// Relative Path: ".\command.exe"
|
||||
// Home Path: "~\command.exe"
|
||||
// Drive Relative Path: "\Users\User\AppData\Local\Temp\command.exe"
|
||||
if (_commandName[0] == '.' || _commandName[0] == '~' || _commandName[0] == '\\')
|
||||
|
||||
char firstChar = _commandName[0];
|
||||
if (firstChar == '.' || firstChar == '~' || firstChar == '\\')
|
||||
{
|
||||
using (CommandDiscovery.discoveryTracer.TraceScope(
|
||||
"{0} appears to be a relative path. Trying to resolve relative path",
|
||||
@@ -1334,10 +1336,6 @@ namespace System.Management.Automation
|
||||
/// </exception>
|
||||
internal LookupPathCollection ConstructSearchPatternsFromName(string name, bool commandDiscovery = false)
|
||||
{
|
||||
Dbg.Assert(
|
||||
!string.IsNullOrEmpty(name),
|
||||
"Caller should verify name");
|
||||
|
||||
var result = new LookupPathCollection();
|
||||
|
||||
// First check to see if the commandName has an extension, if so
|
||||
|
||||
@@ -178,5 +178,14 @@ Describe "Get-Command" -Tag CI {
|
||||
|
||||
$Result | Should -BeOfType [System.Management.Automation.CommandInfo]
|
||||
}
|
||||
|
||||
It "Throws '<expected>' exception if '<Name>' name is used" -TestCases @(
|
||||
@{ Name = 'space'; Value = ' '; expected = "CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand" }
|
||||
@{ Name = 'empty'; Value = ''; expected = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetCommandCommand" }
|
||||
@{ Name = 'null'; Value = $null; expected = "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetCommandCommand" }
|
||||
) {
|
||||
param($value, $expected)
|
||||
{ Get-Command $value -ErrorAction Stop } | Should -Throw -ErrorId $expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user