Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/SavePSResourceTests/SavePSResourceV2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
6 changes: 6 additions & 0 deletions test/SavePSResourceTests/SavePSResourceV3.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Loading