Skip to content

Commit

Permalink
Add special casing for gifs and base64 encoded images.
Browse files Browse the repository at this point in the history
* Relates to imgflo/imgflo#85.
  • Loading branch information
paulyoung committed Sep 11, 2015
1 parent 01185d3 commit 96f095c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ImgFlo/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions ImgFloTests/ClientSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
}

0 comments on commit 96f095c

Please sign in to comment.