Skip to content

Commit 06b4384

Browse files
authored
Filter out path separators in package names (#1916)
1 parent 79404f3 commit 06b4384

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/code/Utils.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,18 @@ public static string[] ProcessNameWildcards(
189189

190190
if (name.Contains("?") || name.Contains("["))
191191
{
192-
errorMsgsList.Add(String.Format("-Name with wildcards '?' and '[' are not supported for this cmdlet so Name entry: {0} will be discarded.", name));
192+
errorMsgsList.Add(String.Format("-Name with wildcards '?' and '[' are not supported for this cmdlet so Name entry: '{0}' will be discarded.", name));
193193
continue;
194194
}
195195

196196
isContainWildcard = true;
197197
namesWithSupportedWildcards.Add(name);
198198
}
199+
else if(name.StartsWith("/") || name.StartsWith("\\"))
200+
{
201+
errorMsgsList.Add(String.Format("-Name starting with path separator '/' or '\\' is not supported for this cmdlet so Name entry: '{0}' will be discarded.", name));
202+
continue;
203+
}
199204
else
200205
{
201206
namesWithSupportedWildcards.Add(name);

test/SavePSResourceTests/SavePSResourceV2.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,10 @@ Describe 'Test HTTP Save-PSResource for V2 Server Protocol' -tags 'CI' {
208208
$pkg.Name | Should -Be $testModuleNameWithLicense
209209
$pkg.Version | Should -Be "2.0"
210210
}
211+
212+
It "Not save module that has path separator in name" {
213+
Save-PSResource -Name "/$testModuleName" -Repository $PSGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository
214+
$err.Count | Should -BeGreaterThan 0
215+
$err[0].FullyQualifiedErrorId | Should -BeExactly 'ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource'
216+
}
211217
}

test/SavePSResourceTests/SavePSResourceV3.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,10 @@ Describe 'Test HTTP Save-PSResource for V3 Server Protocol' -tags 'CI' {
159159
$res = Save-PSResource 'TestModuleWithDependencyE' -Repository $NuGetGalleryName -TrustRepository -PassThru
160160
$res.Length | Should -Be 4
161161
}
162+
163+
It "Not save module that has path separator in name" {
164+
Save-PSResource -Name "/$testModuleName" -Repository $NuGetGalleryName -Path $SaveDir -ErrorVariable err -ErrorAction SilentlyContinue -TrustRepository
165+
$err.Count | Should -BeGreaterThan 0
166+
$err[0].FullyQualifiedErrorId | Should -BeExactly 'ErrorFilteringNamesForUnsupportedWildcards,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource'
167+
}
162168
}

0 commit comments

Comments
 (0)