Add 'NullReference' checks to two code paths related to 'PseudoParameterBinder' (#5738)
1. Add a null check in the tab completion code on the binding result returned from `PseudoParameterBinder`; 2. Add a null check in `CommandDiscovery.LookupCommandProcessor` on the `CommandInfo` object returned from the method `LookupCommandInfo`.
This commit is contained in:
parent
80d5df55c2
commit
5f202d676f
|
@ -6180,6 +6180,11 @@ namespace System.Management.Automation
|
|||
if (commandAst != null)
|
||||
{
|
||||
var binding = new PseudoParameterBinder().DoPseudoParameterBinding(commandAst, null, null, bindingType: PseudoParameterBinder.BindingType.ArgumentCompletion);
|
||||
if (binding == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string parameterName = null;
|
||||
foreach (var boundArg in binding.BoundArguments)
|
||||
{
|
||||
|
|
|
@ -300,11 +300,15 @@ namespace System.Management.Automation
|
|||
internal CommandProcessorBase LookupCommandProcessor(string commandName,
|
||||
CommandOrigin commandOrigin, bool? useLocalScope)
|
||||
{
|
||||
CommandProcessorBase processor = null;
|
||||
CommandInfo commandInfo = LookupCommandInfo(commandName, commandOrigin);
|
||||
CommandProcessorBase processor = LookupCommandProcessor(commandInfo, commandOrigin, useLocalScope, null);
|
||||
|
||||
// commandInfo.Name might be different than commandName - restore the original invocation name
|
||||
processor.Command.MyInvocation.InvocationName = commandName;
|
||||
if (commandInfo != null)
|
||||
{
|
||||
processor = LookupCommandProcessor(commandInfo, commandOrigin, useLocalScope, null);
|
||||
// commandInfo.Name might be different than commandName - restore the original invocation name
|
||||
processor.Command.MyInvocation.InvocationName = commandName;
|
||||
}
|
||||
|
||||
return processor;
|
||||
}
|
||||
|
|
|
@ -424,6 +424,7 @@ Describe "TabCompletion" -Tags CI {
|
|||
@{ inputStr = 'cd "$pshome\Modu"'; expected = "`"$(Join-Path $PSHOME 'Modules')`""; setup = $null }
|
||||
@{ inputStr = '$PSHOME\System.Management.Au'; expected = Join-Path $PSHOME 'System.Management.Automation.dll'; setup = $null }
|
||||
@{ inputStr = '"$PSHOME\System.Management.Au"'; expected = "`"$(Join-Path $PSHOME 'System.Management.Automation.dll')`""; setup = $null }
|
||||
@{ inputStr = '& "$PSHOME\System.Management.Au"'; expected = "`"$(Join-Path $PSHOME 'System.Management.Automation.dll')`""; setup = $null }
|
||||
## tab completion AST-based tests
|
||||
@{ inputStr = 'get-date | ForEach-Object { $PSItem.h'; expected = 'Hour'; setup = $null }
|
||||
@{ inputStr = '$a=gps;$a[0].h'; expected = 'Handle'; setup = $null }
|
||||
|
|
Loading…
Reference in a new issue