8000 Revert "Allow empty prefix string in 'Import-Module -Prefix' to overr… · PowerShell/PowerShell@2fc4821 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2fc4821

Browse files
authored
Revert "Allow empty prefix string in 'Import-Module -Prefix' to override default prefix in manifest (#20409)" (#25462)
1 parent ca7038b commit 2fc4821

File tree

2 files changed

+11
-13
lines changed
8000

2 files changed

+11
-13
lines changed

src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,17 @@ internal PSModuleInfo LoadModuleManifest(
16201620
if (bailOnFirstError) return null;
16211621
}
16221622

1623-
string resolvedCommandPrefix = BasePrefix ?? defaultCommandPrefix ?? string.Empty;
1623+
string resolvedCommandPrefix = string.Empty;
1624+
1625+
if (!string.IsNullOrEmpty(defaultCommandPrefix))
1626+
{
1627+
resolvedCommandPrefix = defaultCommandPrefix;
1628+
}
16 8000 29+
1630+
if (!string.IsNullOrEmpty(this.BasePrefix))
1631+
{
1632+
resolvedCommandPrefix = this.BasePrefix;
1633+
}
16241634

16251635
if (!string.IsNullOrEmpty(actualRootModule))
16261636
{

test/powershell/Modules/Microsoft.PowerShell.Core/Import-Module.Tests.ps1

-12
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ Describe "Import-Module" -Tags "CI" {
5757
(Get-Module TestModule).Version | Should -BeIn "1.1"
5858
}
5959

60-
61-
It 'Should override default command prefix if an empty string is provided' {
62-
$ModuleName = "PrefixTestModule"
< 8000 div aria-hidden="true" style="left:-2px" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__in-progress-comment-indicator--hx3m3">
63-
$ModulePath = Join-Path -Path $testdrive -ChildPath $ModuleName
64-
$null = New-Item -Path $ModulePath -ItemType Directory -Force
65-
'function Use-Something{}' | Set-Content -Path "$ModulePath\$ModuleName.psm1" -Force
66-
New-ModuleManifest -Path "$ModulePath\$ModuleName.psd1" -DefaultCommandPrefix MyPrefix -FunctionsToExport Use-Something -RootModule "$ModuleName.psm1"
67-
$ImportedModule = Import-Module -Name "$ModulePath\$ModuleName.psd1" -Prefix "" -PassThru
68-
$ImportedModule.ExportedCommands.ContainsKey('Use-Something') | Should -Be $true
69-
Remove-Module -ModuleInfo $ImportedModule
70-
}
71-
7260
It 'ProcessorArchitecture should work' {
7361
$currentProcessorArchitecture = switch ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) {
7462
'X86' { 'x86' }

0 commit comments

Comments
 (0)
0