From 5e91d82b1046125d7258f1945e07eb46cb92195e Mon Sep 17 00:00:00 2001 From: anamnavi Date: Mon, 24 Nov 2025 18:04:02 -0500 Subject: [PATCH 1/2] Filter out path separators in package names --- src/code/Utils.cs | 7 ++++++- test/SavePSResourceTests/SavePSResourceV2.Tests.ps1 | 6 ++++++ test/SavePSResourceTests/SavePSResourceV3.Tests.ps1 | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index cc6f0fa14..545696e5e 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -189,13 +189,18 @@ public static string[] ProcessNameWildcards( if (name.Contains("?") || name.Contains("[")) { - errorMsgsList.Add(String.Format("-Name with wildcards '?' and '[' are not supported for this cmdlet so Name entry: {0} will be discarded.", name)); + errorMsgsList.Add(String.Format("-Name with wildcards '?' and '[' are not supported for this cmdlet so Name entry: '{0}' will be discarded.", name)); continue; } isContainWildcard = true; namesWithSupportedWildcards.Add(name); } + else if(name.Contains("/") || name.Contains("\\")) + { + errorMsgsList.Add(String.Format("-Name with path separator '/' or '\\' is not supported for this cmdlet so Name entry: '{0}' will be discarded.", name)); + continue; + } else { namesWithSupportedWildcards.Add(name); diff --git a/test/SavePSResourceTests/SavePSResourceV2.Tests.ps1 b/test/SavePSResourceTests/SavePSResourceV2.Tests.ps1 index 609c73e3d..4b0269d82 100644 --- a/test/SavePSResourceTests/SavePSResourceV2.Tests.ps1 +++ b/test/SavePSResourceTests/SavePSResourceV2.Tests.ps1 @@ -208,4 +208,10 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' { $pkg.Name | Should -Be $testModuleNameWithLicense $pkg.Version | Should -Be "2.0" } + + It "Not save module that has path separator in name" { + Save-PSResource -Name "/$testModuleName" -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly 'ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource' + } } diff --git a/test/SavePSResourceTests/SavePSResourceV3.Tests.ps1 b/test/SavePSResourceTests/SavePSResourceV3.Tests.ps1 index 037ed1674..f4118d265 100644 --- a/test/SavePSResourceTests/SavePSResourceV3.Tests.ps1 +++ b/test/SavePSResourceTests/SavePSResourceV3.Tests.ps1 @@ -159,4 +159,10 @@ Describe 'Test HTTP Save-PSResource for V3 Server Protocol' -tags 'CI' { $res = Save-PSResource 'TestModuleWithDependencyE' -Repository $NuGetGalleryName -TrustRepository -PassThru $res.Length | Should -Be 4 } + + It "Not save module that has path separator in name" { + Save-PSResource -Name "/$testModuleName" -Repository $NuGetGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository + $err.Count | Should -BeGreaterThan 0 + $err[0].FullyQualifiedErrorId | Should -BeExactly 'ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource' + } } From 092b95f8dc83101a0c4b42bd5034742c3b14062c Mon Sep 17 00:00:00 2001 From: anamnavi Date: Tue, 2 Dec 2025 11:48:27 -0500 Subject: [PATCH 2/2] fix condition for path separator to account for module prefix scenarios for container registries --- src/code/Utils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 545696e5e..29e321a14 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -196,9 +196,9 @@ public static string[] ProcessNameWildcards( isContainWildcard = true; namesWithSupportedWildcards.Add(name); } - else if(name.Contains("/") || name.Contains("\\")) + else if(name.StartsWith("/") || name.StartsWith("\\")) { - errorMsgsList.Add(String.Format("-Name with path separator '/' or '\\' is not supported for this cmdlet so Name entry: '{0}' will be discarded.", name)); + errorMsgsList.Add(String.Format("-Name starting with path separator '/' or '\\' is not supported for this cmdlet so Name entry: '{0}' will be discarded.", name)); continue; } else