Skip to content

Commit b10666d

Browse files
committed
Fix "." and ".." in archives being extracted wrong
1 parent 1ce8769 commit b10666d

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/Files.App/Actions/Content/Archives/Decompress/BaseDecompressArchiveAction.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,29 @@ protected async Task DecompressArchiveHereAsync(bool smart = false)
9191
if (zipFile is null)
9292
return true;
9393

94-
return zipFile.ArchiveFileData.Select(file =>
94+
static string? GetFirstMeaningfulSegment(string? fileName)
9595
{
96-
var pathCharIndex = file.FileName.IndexOfAny(['/', '\\']);
97-
if (pathCharIndex == -1)
98-
return file.FileName;
99-
else
100-
return file.FileName.Substring(0, pathCharIndex);
101-
})
102-
.Distinct().Count() > 1;
96+
if (string.IsNullOrEmpty(fileName))
97+
return null;
98+
99+
var parts = fileName.Split(['/', '\\'], StringSplitOptions.RemoveEmptyEntries);
100+
foreach (var part in parts)
101+
{
102+
if (part is "." or "..")
103+
continue;
104+
return part;
105+
}
106+
107+
return null;
108+
}
109+
110+
var topLevelEntries = zipFile.ArchiveFileData
111+
.Select(file => GetFirstMeaningfulSegment(file.FileName))
112+
.Where(x => !string.IsNullOrEmpty(x))
113+
.Distinct()
114+
.Count();
115+
116+
return topLevelEntries > 1;
103117
});
104118

105119
if (smart && currentFolder is not null && isMultipleItems)

0 commit comments

Comments
 (0)