Browse Source

Merge pull request #176 from onevcat/fix/ignore-empty-url

Ignore empty url
Wei Wang 10 years ago
parent
commit
d376d5ecd9
2 changed files with 15 additions and 2 deletions
  1. 2 2
      Kingfisher/ImageDownloader.swift
  2. 13 0
      KingfisherTests/ImageDownloaderTests.swift

+ 2 - 2
Kingfisher/ImageDownloader.swift

@@ -196,8 +196,8 @@ public extension ImageDownloader {
         
         
         self.requestModifier?(request)
         self.requestModifier?(request)
         
         
-        // There is a possiblility that request modifier changed the url to `nil`
-        if request.URL == nil {
+        // There is a possiblility that request modifier changed the url to `nil` or empty.
+        if request.URL == nil || request.URL!.absoluteString.isEmpty {
             completionHandler?(image: nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidURL.rawValue, userInfo: nil), imageURL: nil, originalData: nil)
             completionHandler?(image: nil, error: NSError(domain: KingfisherErrorDomain, code: KingfisherError.InvalidURL.rawValue, userInfo: nil), imageURL: nil, originalData: nil)
             return
             return
         }
         }

+ 13 - 0
KingfisherTests/ImageDownloaderTests.swift

@@ -206,4 +206,17 @@ class ImageDownloaderTests: XCTestCase {
         
         
         waitForExpectationsWithTimeout(5, handler: nil)
         waitForExpectationsWithTimeout(5, handler: nil)
     }
     }
+    
+    func testDownloadEmptyURL() {
+        let expectation = expectationWithDescription("wait for downloading error")
+        
+        downloader.downloadImageWithURL(NSURL(string: "")!, progressBlock: { (receivedSize, totalSize) -> () in
+            XCTFail("The progress block should not be called.")
+            }) { (image, error, imageURL, originalData) -> () in
+                XCTAssertNotNil(error, "An error should happen for empty URL")
+                XCTAssertEqual(error!.code, KingfisherError.InvalidURL.rawValue)
+                expectation.fulfill()
+        }
+        waitForExpectationsWithTimeout(5, handler: nil)
+    }
 }
 }