Skip to content

Commit

Permalink
Merge #3893 Handle backslashes in ZIP paths
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 13, 2023
2 parents 164d88a + 46cc108 commit 644c2cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ All notable changes to this project will be documented in this file.
- [Core] Make where-CKAN-would-install logic consistent (#3931 by: HebaruSan; reviewed: techman83)
- [Multiple] Improve provides prompt usability, with bugfixes (#3934 by: HebaruSan; reviewed: JonnyOThan)
- [GUI] Fix two small typos in Resources.pt-BR.resx at line 182 (#3943 by: idrkwhattoput; reviewed: HebaruSan)
- [Core] Handle backslashes in ZIP paths (#3893 by: HebaruSan; reviewed: techman83)

### Internal

Expand Down
9 changes: 7 additions & 2 deletions Core/Types/ModuleInstallDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,13 @@ public List<InstallableFile> FindInstallableFiles(ZipFile zipfile, GameInstance
// Surely there's a better way, although this is fast enough we may not care.
foreach (ZipEntry entry in zipfile)
{
// Backslashes are not allowed in filenames according to the ZIP spec,
// but there's a non-conformant PowerShell tool that uses them anyway.
// Try to accommodate those mods.
string entryName = entry.Name.Replace('\\', '/');

// Skips dirs and things not prescribed by our install stanza.
if (!IsWanted(entry.Name, shortestMatch))
if (!IsWanted(entryName, shortestMatch))
{
continue;
}
Expand All @@ -447,7 +452,7 @@ public List<InstallableFile> FindInstallableFiles(ZipFile zipfile, GameInstance
// Get the full name of the file.
// Update our file info with the install location
file_info.destination = TransformOutputName(
ksp.game, entry.Name, installDir, @as);
ksp.game, entryName, installDir, @as);
file_info.makedir = AllowDirectoryCreation(
ksp.game,
ksp?.ToRelativeGameDir(file_info.destination)
Expand Down
4 changes: 4 additions & 0 deletions Netkan/Validators/InstallValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public void Validate(Metadata metadata)
if (stanza.ContainsKey(propName))
{
string val = (string)stanza[propName];
if (string.IsNullOrEmpty(val))
{
throw new Kraken($"Install property '{propName}' is null or empty");
}
string norm = CKANPathUtils.NormalizePath(val);
if (val != norm)
{
Expand Down

0 comments on commit 644c2cb

Please sign in to comment.