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
10 changes: 4 additions & 6 deletions src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ private bool ShouldSkipCommandResolutionForConstrainedLanguage(CommandInfo? resu
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
Expand All @@ -1099,7 +1099,9 @@ private bool ShouldSkipCommandResolutionForConstrainedLanguage(CommandInfo? resu
// 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",
Expand Down Expand Up @@ -1334,10 +1336,6 @@ private bool ShouldSkipCommandResolutionForConstrainedLanguage(CommandInfo? resu
/// </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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}