Fix a null reference crash in completion code (#19916)

This commit is contained in:
MartinGC94
2023-07-10 12:31:27 -07:00
committed by GitHub
parent 1fd1ab7bb0
commit c5cc8c8bbc
2 changed files with 19 additions and 1 deletions
@@ -87,4 +87,21 @@ Describe "Tab completion bug fix" -Tags "CI" {
$result.CompletionMatches[0].CompletionText | Should -BeExactly 'Ascending'
$result.CompletionMatches[1].CompletionText | Should -BeExactly 'Descending'
}
It "Issue#19912 - Tab completion should not crash" {
$ISS = [initialsessionstate]::CreateDefault()
$Runspace = [runspacefactory]::CreateRunspace($ISS)
$Runspace.Open()
$OldRunspace = [runspace]::DefaultRunspace
try
{
[runspace]::DefaultRunspace = $Runspace
{[System.Management.Automation.CommandCompletion]::CompleteInput('Get-', 3, $null)} | Should -Not -Throw
}
finally
{
[runspace]::DefaultRunspace = $OldRunspace
$Runspace.Dispose()
}
}
}