Guard against null or blank path components when adding to module path (#19922)

This commit is contained in:
stevenebutler
2023-07-31 11:00:27 -07:00
committed by GitHub
parent 2c6777b4b9
commit 3710671c16
3 changed files with 41 additions and 16 deletions
@@ -247,3 +247,21 @@ Describe "ModuleIntrinsics.GetPSModulePath API tests" -tag @('CI', 'RequireAdmin
$currentModulePathElements | Should -Contain $mPath
}
}
Describe 'ModuleIntrinsics.GetModulePath environment interaction' -tag @('CI') {
It "GetModulePath does not crash when MyDocuments special folder is empty" {
try {
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('SetMyDocumentsSpecialFolderToBlank', $true)
[System.Management.Automation.ModuleIntrinsics]::GetModulePath($null, $null, $null)
}
finally {
[System.Management.Automation.Internal.InternalTestHooks]::SetTestHook('SetMyDocumentsSpecialFolderToBlank', $false)
}
}
It "GetModulePath does not crash when MyDocuments special folder is not empty" {
[System.Management.Automation.ModuleIntrinsics]::GetModulePath($null, $null, $null)
}
}