Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,42 @@ internal bool LoadUsingModulePath(PSModuleInfo parentModule, bool found, IEnumer
// Now search using the module path...
foreach (string path in modulePath)
{
// a name takes the form of .../moduleDir/moduleName.<ext>
// if only one name has been specified, then the moduleDir
// and moduleName are identical and repeated...
// Also append th ename if the path currently points at a directory
string qualifiedPath = Path.Combine(path, fileBaseName);

// Load the latest valid version if it is a multi-version module directory
module = LoadUsingMultiVersionModuleBase(qualifiedPath, manifestProcessingFlags, options, out found);

if (!found)
#if UNIX
foreach (string folder in Directory.EnumerateDirectories(path))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method appears to be only implemented for Win32. Since this path is only for UNIX, I'll leave it as-is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

{
if (name.IndexOfAny(Utils.Separators.Directory) == -1)
string moduleName = Path.GetFileName(folder);
if (String.Compare(moduleName, fileBaseName, StringComparison.OrdinalIgnoreCase) == 0)
{
qualifiedPath = Path.Combine(qualifiedPath, fileBaseName);
fileBaseName = moduleName;
#endif
string qualifiedPath = Path.Combine(path, fileBaseName);
module = LoadUsingMultiVersionModuleBase(qualifiedPath, manifestProcessingFlags, options, out found);
if (!found)
{
if (name.IndexOfAny(Utils.Separators.Directory) == -1)
{
qualifiedPath = Path.Combine(qualifiedPath, fileBaseName);
}
else if (Utils.NativeDirectoryExists(qualifiedPath))
{
// if it points to a directory, add the basename back onto the path...
qualifiedPath = Path.Combine(qualifiedPath, Path.GetFileName(fileBaseName));
}

module = LoadUsingExtensions(parentModule, name, qualifiedPath, extension, null, this.BasePrefix, ss, options, manifestProcessingFlags, out found);
}
#if UNIX
}
else if (Directory.Exists(qualifiedPath))
if (found)
{
// if it points to a directory, add the basename back onto the path...
qualifiedPath = Path.Combine(qualifiedPath, Path.GetFileName(fileBaseName));
break;
}

module = LoadUsingExtensions(parentModule, name, qualifiedPath, extension, null, this.BasePrefix, ss, options, manifestProcessingFlags, out found);
}

if (found)
{
break;
}
#endif
}

if (found)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ using System.Management.Automation; // Windows PowerShell namespace.

namespace ModuleCmdlets
{
[Cmdlet(VerbsDiagnostic.Test,"BinaryModuleCmdlet1")]
[Cmdlet(VerbsDiagnostic.Test,"BinaryModuleCmdlet1")]
public class TestBinaryModuleCmdlet1Command : Cmdlet
{
protected override void BeginProcessing()
Expand All @@ -124,3 +124,41 @@ namespace ModuleCmdlets
}
}

Describe "Import-Module should be case insensitive" -Tags 'CI' {
BeforeAll {
$defaultPSModuleAutoloadingPreference = $PSModuleAutoloadingPreference
$originalPSModulePath = $env:PSModulePath.Clone()
$modulesPath = "$TestDrive\Modules"
$env:PSModulePath += [System.IO.Path]::PathSeparator + $modulesPath
$PSModuleAutoloadingPreference = "none"
}

AfterAll {
$global:PSModuleAutoloadingPreference = $defaultPSModuleAutoloadingPreference
$env:PSModulePath = $originalPSModulePath
}

AfterEach {
Remove-Item -Recurse -Path $modulesPath -Force -ErrorAction SilentlyContinue
}

It "Import-Module can import a module using different casing using '<modulePath>' and manifest:<manifest>" -TestCases @(
@{modulePath="TESTMODULE/1.1"; manifest=$true},
@{modulePath="TESTMODULE" ; manifest=$true},
@{modulePath="TESTMODULE" ; manifest=$false}
) {
param ($modulePath, $manifest)
New-Item -ItemType Directory -Path "$modulesPath/$modulePath" -Force > $null
if ($manifest) {
New-ModuleManifest -Path "$modulesPath/$modulePath/TESTMODULE.psd1" -RootModule "TESTMODULE.psm1" -ModuleVersion 1.1
}
Set-Content -Path "$modulesPath/$modulePath/TESTMODULE.psm1" -Value "function mytest { 'hello' }"
Import-Module testMODULE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe -Force to ensure you are not loading a cached version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, as part of this test, I'm removing the module with a different casing, so I don't want to -force loading

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

$m = Get-Module TESTmodule
$m | Should BeOfType "System.Management.Automation.PSModuleInfo"
$m.Name | Should Be "TESTMODULE"
mytest | Should BeExactly "hello"
Remove-Module TestModule
Get-Module tESTmODULE | Should BeNullOrEmpty
}
}