Support importing module paths that end in trailing directory separator (#6602)

This commit is contained in:
Steve Lee 2018-04-12 21:07:50 -07:00 committed by Ilya
parent f96a928a42
commit c2accff785
2 changed files with 16 additions and 0 deletions

View file

@ -629,6 +629,12 @@ namespace Microsoft.PowerShell.Commands
}
else if (Directory.Exists(rootedPath))
{
// If the path ends with a directory separator, remove it
if (rootedPath.EndsWith(Path.DirectorySeparatorChar))
{
rootedPath = Path.GetDirectoryName(rootedPath);
}
// Load the latest valid version if it is a multi-version module directory
foundModule = LoadUsingMultiVersionModuleBase(rootedPath,
ManifestProcessingFlags.LoadElements |

View file

@ -18,6 +18,7 @@ Describe "Import-Module" -Tags "CI" {
BeforeEach {
Remove-Module -Name $moduleName -Force
(Get-Module -Name $moduleName).Name | Should -BeNullOrEmpty
Remove-Module -Name TestModule -Force -ErrorAction SilentlyContinue
}
AfterEach {
@ -30,6 +31,15 @@ Describe "Import-Module" -Tags "CI" {
(Get-Module -Name $moduleName).Name | Should -BeExactly $moduleName
}
It "should be able to load a module with a trailing directory separator: <modulePath>" -TestCases @(
@{ modulePath = (Get-Module -ListAvailable $moduleName).ModuleBase + [System.IO.Path]::DirectorySeparatorChar; expectedName = $moduleName },
@{ modulePath = Join-Path -Path $TestDrive -ChildPath "\Modules\TestModule\"; expectedName = "TestModule" }
) {
param( $modulePath, $expectedName )
{ Import-Module -Name $modulePath -ErrorAction Stop } | Should -Not -Throw
(Get-Module -Name $expectedName).Name | Should -BeExactly $expectedName
}
It "should be able to add a module with using ModuleInfo switch" {
$a = Get-Module -ListAvailable $moduleName
{ Import-Module -ModuleInfo $a } | Should -Not -Throw