diff --git a/ImgFlo/Client.swift b/ImgFlo/Client.swift index 0f746f9..4c38da5 100644 --- a/ImgFlo/Client.swift +++ b/ImgFlo/Client.swift @@ -17,6 +17,18 @@ public struct Client { return .None } + guard let URL = NSURL(string: URLString) else { + return .None + } + + guard URL.scheme != "data" else { + return URL + } + + guard URL.pathExtension != "gif" else { + return URL + } + let input = NSURLQueryItem(name: "input", value: URLString) components.queryItems = [ input ] + graph.queryItems @@ -28,7 +40,7 @@ public struct Client { if let providedFormat = format { derivedFormat = providedFormat - } else if let pathExtension = NSURL(string: URLString)?.pathExtension where !pathExtension.isEmpty { + } else if let pathExtension = URL.pathExtension where !pathExtension.isEmpty { derivedFormat = pathExtension.lowercaseString == "jpg:large" ? "jpg" : pathExtension } else { derivedFormat = nil diff --git a/ImgFloTests/ClientSpec.swift b/ImgFloTests/ClientSpec.swift index 3d84d6a..54645e9 100644 --- a/ImgFloTests/ClientSpec.swift +++ b/ImgFloTests/ClientSpec.swift @@ -116,6 +116,26 @@ class ClientSpec: QuickSpec { expect(URL?.absoluteString).to(equal(expected)) } } + + context("with a .gif extension") { + it("should return the original URL") { + let graph: Graph = .Passthrough(width: 720, height: nil) + let input = "http://www.reactiongifs.com/wp-content/uploads/2013/11/I-have-no-idea-what-I-am-doing.gif" + let URL = imgflo.getURL(graph, input) + + expect(URL?.absoluteString).to(equal(input)) + } + } + + context("with a data: scheme") { + it("should return the original URL") { + let graph: Graph = .Passthrough(width: 720, height: nil) + let input = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAABAAEDAREAAhEBAxEB/8QAFAABAAAAAAAAAAAAAAAAAAAACv/EABQQAQAAAAAAAAAAAAAAAAAAAAD/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AWAD/2Q==" + let URL = imgflo.getURL(graph, input) + + expect(URL?.absoluteString).to(equal(input)) + } + } } } }