@@ -414,7 +414,7 @@ function Expand-Archive
414
414
{
415
415
# delete the expanded file/directory as the archive
416
416
# file was not completly expanded.
417
- $expandedItems | % { Remove-Item $_ - Force - Recurse }
417
+ $expandedItems | % { Remove-Item " $_ " - Force - Recurse }
418
418
}
419
419
}
420
420
elseif ($PassThru -and $expandedItems.Count -gt 0 )
@@ -1007,6 +1007,9 @@ function ExpandArchiveHelper
1007
1007
# If the Parent directory of the current entry in the archive file does not exist, then create it.
1008
1008
if ($parentDirExists -eq $false )
1009
1009
{
1010
+ # note that if any ancestor of this directory doesn't exist, we don't recursively create each one as New-Item
1011
+ # takes care of this already, so only one DirectoryInfo is returned instead of one for each parent directory
1012
+ # that only contains directories
1010
1013
New-Item $currentArchiveEntryFileInfo.DirectoryName - Type Directory - Confirm:$isConfirm | Out-Null
1011
1014
1012
1015
if (! (Test-Path - LiteralPath $currentArchiveEntryFileInfo.DirectoryName - PathType Container))
@@ -1056,6 +1059,11 @@ function ExpandArchiveHelper
1056
1059
1057
1060
if (! $hasNonTerminatingError )
1058
1061
{
1062
+ # The ExtractToFile() method doesn't handle whitespace correctly, strip whitespace which is consistent with how Explorer handles archives
1063
+ # There is an edge case where an archive contains files whose only difference is whitespace, but this is uncommon and likely not legitimate
1064
+ [string []] $parts = $currentArchiveEntryPath.Split ([System.IO.Path ]::DirectorySeparatorChar) | % { $_.Trim () }
1065
+ $currentArchiveEntryPath = [string ]::Join([System.IO.Path ]::DirectorySeparatorChar, $parts )
1066
+
1059
1067
[System.IO.Compression.ZipFileExtensions ]::ExtractToFile($currentArchiveEntry , $currentArchiveEntryPath , $false )
1060
1068
1061
1069
# Add the expanded file path to the $expandedItems array,
0 commit comments