Commit 977af1db authored by Roy Marmelstein's avatar Roy Marmelstein

Merge branch 'jozsef-vesza-include-cbz'

parents 82686f86 d9bf08dc
...@@ -66,7 +66,7 @@ public class Zip { ...@@ -66,7 +66,7 @@ public class Zip {
guard let path = zipFilePath.path where destination.path != nil else { guard let path = zipFilePath.path where destination.path != nil else {
throw ZipError.FileNotFound throw ZipError.FileNotFound
} }
if fileManager.fileExistsAtPath(path) == false || zipFilePath.pathExtension != "zip" { if fileManager.fileExistsAtPath(path) == false || fileExtensionIsInvalid(zipFilePath.pathExtension) {
throw ZipError.FileNotFound throw ZipError.FileNotFound
} }
...@@ -303,6 +303,18 @@ public class Zip { ...@@ -303,6 +303,18 @@ public class Zip {
progressTracker.completedUnitCount = Int64(totalSize) progressTracker.completedUnitCount = Int64(totalSize)
} }
/**
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
...@@ -209,5 +209,15 @@ class ZipTests: XCTestCase { ...@@ -209,5 +209,15 @@ class ZipTests: XCTestCase {
} }
} }
func testFileExtensionIsInvalidForValidUrl() {
let fileUrl = NSURL(string: "file.cbz")
let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension)
XCTAssertFalse(result)
}
func testFileExtensionIsInvalidForInvalidUrl() {
let fileUrl = NSURL(string: "file.xyz")
let result = Zip.fileExtensionIsInvalid(fileUrl?.pathExtension)
XCTAssertTrue(result)
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment