Skip to content

Commit

Permalink
Fix Windows file name validation in Zip.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Oct 2, 2024
1 parent 1e23b68 commit ac17fc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ public class Zip {
var pathString = String(cString: fileName)

#if os(Windows)
// Colons are not allowed in Windows file names.
pathString = pathString.replacingOccurrences(of: ":", with: "_")
guard pathString.rangeOfCharacter(from: ["<", ">", ":", "\"", "/", "\\", "|", "?", "*",]) == nil else {
throw ZipError.unzipFail
}
#endif

guard !pathString.isEmpty else {
Expand Down
4 changes: 4 additions & 0 deletions Tests/ZipTests/ZipTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ final class ZipTests: XCTestCase {

// Tests if https://github.com/vapor-community/Zip/issues/4 does not occur anymore.
func testRoundTripping() throws {
#if os(Windows)
XCTExpectFailure("This Zip file contains reserved characters that are not allowed on Windows.")
#endif

// "prod-apple-swift-metrics-main-e6a00d36.zip" is the original zip file from the issue.
let zipFilePath = url(forResource: "prod-apple-swift-metrics-main-e6a00d36", withExtension: "zip")!
let failDestinationPath = try autoRemovingSandbox()
Expand Down

0 comments on commit ac17fc7

Please sign in to comment.