diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index ba7fc3d88..d804da16a 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -1203,7 +1203,7 @@ private bool TryExtractToDirectory(string zipPath, string extractPath, out Error { using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { - foreach (ZipArchiveEntry entry in archive.Entries) + foreach (ZipArchiveEntry entry in archive.Entries.Where(entry => entry.CompressedLength > 0)) { // If a file has one or more parent directories. if (entry.FullName.Contains(Path.DirectorySeparatorChar) || entry.FullName.Contains(Path.AltDirectorySeparatorChar)) diff --git a/test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1 b/test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1 index 7553fa066..90b264983 100644 --- a/test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1 +++ b/test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1 @@ -14,12 +14,15 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' { BeforeAll { $localRepo = "psgettestlocal" $localUNCRepo = "psgettestlocal3" + $localNupkgRepo = "LocalNupkgRepo" + $localNupkgRepoUri = "test\testFiles\testNupkgs" $testModuleName = "test_local_mod" $testModuleName2 = "test_local_mod2" $testModuleClobber = "testModuleClobber" $testModuleClobber2 = "testModuleClobber2" Get-NewPSResourceRepositoryFile Register-LocalRepos + Register-PSResourceRepository -Name $localNupkgRepo -SourceLocation $localNupkgRepoUri $prereleaseLabel = "alpha001" $tags = @() @@ -279,4 +282,13 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' { $err[$i].FullyQualifiedErrorId | Should -Not -Be "System.NullReferenceException,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource" } } + + It "Install .nupkg that contains directories (specific package throws errors when accessed by ZipFile.OpenRead)" { + $nupkgName = "Microsoft.Web.Webview2" + $nupkgVersion = "1.0.2792.45" + Install-PSResource -Name $nupkgName -Version $nupkgVersion -Repository $localNupkgRepo -TrustRepository + $pkg = Get-InstalledPSResource $nupkgName + $pkg.Name | Should -Be $nupkgName + $pkg.Version | Should -Be $nupkgVersion + } } diff --git a/test/testFiles/testNupkgs/microsoft.web.webview2.1.0.2792.45.nupkg b/test/testFiles/testNupkgs/microsoft.web.webview2.1.0.2792.45.nupkg new file mode 100644 index 000000000..d047ae55d Binary files /dev/null and b/test/testFiles/testNupkgs/microsoft.web.webview2.1.0.2792.45.nupkg differ