diff --git a/Zip.xcodeproj/project.pbxproj b/Zip.xcodeproj/project.pbxproj index 9bd4a3a7b689fbe4c12d9abcb0e9d9978a865505..05b360c360e8c6843709520e7c69d2522c195843 100644 --- a/Zip.xcodeproj/project.pbxproj +++ b/Zip.xcodeproj/project.pbxproj @@ -79,6 +79,8 @@ 347E3AD81C1E04C900A11FD3 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; }; 34940A241C58876200D41574 /* 3crBXeO.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A221C58876200D41574 /* 3crBXeO.gif */; }; 34940A251C58876200D41574 /* kYkLkPf.gif in Resources */ = {isa = PBXBuildFile; fileRef = 34940A231C58876200D41574 /* kYkLkPf.gif */; }; + BBF824D51CA60383008FF3C5 /* bb8.cbz in Resources */ = {isa = PBXBuildFile; fileRef = BBF824D31CA60383008FF3C5 /* bb8.cbz */; }; + BBF824D61CA60383008FF3C5 /* bb8.xyz in Resources */ = {isa = PBXBuildFile; fileRef = BBF824D41CA60383008FF3C5 /* bb8.xyz */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -143,6 +145,8 @@ 347E3AD71C1E04C900A11FD3 /* Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip.swift; sourceTree = ""; }; 34940A221C58876200D41574 /* 3crBXeO.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = 3crBXeO.gif; path = Images/3crBXeO.gif; sourceTree = ""; }; 34940A231C58876200D41574 /* kYkLkPf.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; name = kYkLkPf.gif; path = Images/kYkLkPf.gif; sourceTree = ""; }; + BBF824D31CA60383008FF3C5 /* bb8.cbz */ = {isa = PBXFileReference; lastKnownFileType = file; path = bb8.cbz; sourceTree = ""; }; + BBF824D41CA60383008FF3C5 /* bb8.xyz */ = {isa = PBXFileReference; lastKnownFileType = file; path = bb8.xyz; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -262,6 +266,8 @@ 347E3A821C1DFFB500A11FD3 /* ZipTests */ = { isa = PBXGroup; children = ( + BBF824D31CA60383008FF3C5 /* bb8.cbz */, + BBF824D41CA60383008FF3C5 /* bb8.xyz */, 34940A221C58876200D41574 /* 3crBXeO.gif */, 34940A231C58876200D41574 /* kYkLkPf.gif */, 3443A3FC1C4AD199004AD173 /* bb8.zip */, @@ -467,9 +473,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + BBF824D51CA60383008FF3C5 /* bb8.cbz in Resources */, 34940A251C58876200D41574 /* kYkLkPf.gif in Resources */, 3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */, 34940A241C58876200D41574 /* 3crBXeO.gif in Resources */, + BBF824D61CA60383008FF3C5 /* bb8.xyz in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Zip/Zip.swift b/Zip/Zip.swift index 38a97adba89646cd56f0fcc1b20482b741ed3658..083e0a3f8c283c341e2f5b5b0e0067717598b6ad 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -64,7 +64,7 @@ public class Zip { guard let path = zipFilePath.path where destination.path != nil else { throw ZipError.FileNotFound } - if fileManager.fileExistsAtPath(path) == false || zipFilePath.pathExtension != "zip" { + if fileManager.fileExistsAtPath(path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) { throw ZipError.FileNotFound } @@ -281,6 +281,17 @@ public class Zip { } } - - + /** + Check if file extension is invalid. + + - parameter fileExtension: A file extension. + + - returns: false if the extension is "zip" or "cbz", otherwise true. + */ + internal class func fileExtensionIsInvalid(fileExtension: String?) -> Bool { + + guard let fileExtension = fileExtension else { return true } + + return ["zip", "cbz"].contains(fileExtension) + } } \ No newline at end of file diff --git a/ZipTests/ZipTests.swift b/ZipTests/ZipTests.swift index 53fe334f054bcdb0d894bd427afc0550c2152234..d839220427bc9d05afb070204954452ec8675203 100644 --- a/ZipTests/ZipTests.swift +++ b/ZipTests/ZipTests.swift @@ -165,5 +165,15 @@ class ZipTests: XCTestCase { } } - + func testFileExtensionIsInvalidForValidUrl() { + let fileUrl = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "cbz") + let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension) + XCTAssertTrue(result) + } + + func testFileExtensionIsInvalidForInvalidUrl() { + let fileUrl = NSBundle(forClass: ZipTests.self).URLForResource("bb8", withExtension: "xyz") + let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension) + XCTAssertFalse(result) + } } diff --git a/ZipTests/bb8.cbz b/ZipTests/bb8.cbz new file mode 100644 index 0000000000000000000000000000000000000000..514266d193061fd851c447a37de608daef3136fa Binary files /dev/null and b/ZipTests/bb8.cbz differ diff --git a/ZipTests/bb8.xyz b/ZipTests/bb8.xyz new file mode 100644 index 0000000000000000000000000000000000000000..514266d193061fd851c447a37de608daef3136fa Binary files /dev/null and b/ZipTests/bb8.xyz differ