Fix constructing PSModulePath if a sub-path has trailing separator (#13147)

* Fix constructing PSModulePath if a sub-path has trailing separator

* skip test on Linux

* Removed test as the system env var needs to be modified to repro

* Add test

* Fix test by comparing against incorrectly created path

* Update test to be cross platform
This commit is contained in:
Steve Lee
2023-05-02 13:04:30 -07:00
committed by GitHub
parent a153446a01
commit 8135167827
2 changed files with 26 additions and 12 deletions
@@ -187,4 +187,18 @@ Describe "SxS Module Path Basic Tests" -tags "CI" {
Remove-Item -Path $userConfigPath -Force
}
}
It 'User PSModulePath has trailing separator' {
if ($IsWindows) {
$validation = "*\$env:SystemDrive\*"
}
else {
$validation = "*//*"
}
$newUserPath = Join-Path $expectedUserPath ([System.IO.Path]::DirectorySeparatorChar)
$env:PSModulePath = $env:PSModulePath.Replace($expectedUserPath, $newUserPath).Replace($expectedSharedPath,"")
$out = & $powershell -noprofile -command '$env:PSModulePath'
$out.Split([System.IO.Path]::PathSeparator, [System.StringSplitOptions]::RemoveEmptyEntries) | Should -Not -BeLike $validation
}
}